Editor formatting
Represent an on/off command such as bold with a pressed button.
Components / Actions
A native two-state button with pressed semantics.
Represent an on/off command such as bold with a pressed button.
Bind a boolean preference and reflect its current value.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const bold = ref(false)
</script>
<template>
<Toggle v-model="bold" variant="outline" aria-label="Bold">B</Toggle>
</template>The button communicates the state with aria-pressed.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const bold = ref(false)
</script>
<template><Toggle v-model="bold" aria-label="Bold" variant="outline"><strong>B</strong></Toggle></template>A text label can provide the accessible name directly.
<script setup lang="ts">
import { ref } from 'vue'
import Toggle from './components/ui/toggle/Toggle.vue'
const showGrid = ref(true)
</script>
<template><Toggle v-model="showGrid">Grid lines</Toggle></template>The most useful props, models, slots, events, and methods for this component.
| Name | Type | Default or requirement |
|---|---|---|
v-model | boolean | false |
variant | default | outline | default |
size | sm | md | lg | md |
disabled | boolean | false |
type | button | submit | reset | button |
default | slot with { pressed } | required |
The native button exposes aria-pressed and data-state. Give it visible text or an ARIA name; disabled toggles cannot update the model and leave the tab order.