Toggle Group
Coordinate one or several pressed actions within a roving focus group.
Usage
Single
Keep one active value while moving and selecting with keyboard or pointer input.
Keep one active value while moving and selecting with keyboard or pointer input.
<!-- Toggle Group / Single -->
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroupItem, ToggleGroupRoot } from '@sectile/vue/toggle-group'
const items = ['left', 'center', 'right']
const value = ref(['left'])
</script>
<template>
<ToggleGroupRoot :items="items" v-model="value">
<ToggleGroupItem v-for="item in items" :key="item" :value="item">{{ item }}</ToggleGroupItem>
</ToggleGroupRoot>
</template>Multiple
Select several values independently without collapsing the existing selection.
Select several values independently without collapsing the existing selection.
<!-- Toggle Group / Multiple -->
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroupItem, ToggleGroupRoot } from '@sectile/vue/toggle-group'
const items = ['bold', 'italic', 'underline']
const value = ref(['bold', 'italic'])
</script>
<template>
<ToggleGroupRoot :items="items" v-model="value" multiple>
<ToggleGroupItem v-for="item in items" :key="item" :value="item">{{ item }}</ToggleGroupItem>
</ToggleGroupRoot>
</template>Controlled
Let the parent own the current value and apply accepted changes back to the component.
Let the parent own the current value and apply accepted changes back to the component.
<!-- Toggle Group / Controlled -->
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroupItem, ToggleGroupRoot } from '@sectile/vue/toggle-group'
const items = ['left', 'center', 'right']
const value = ref(['left'])
</script>
<template>
<ToggleGroupRoot :items="items" v-model="value">
<ToggleGroupItem v-for="item in items" :key="item" :value="item">{{ item }}</ToggleGroupItem>
</ToggleGroupRoot>
</template>API
Vue package: @sectile/vue/toggle-group
ToggleGroupRootToggleGroupItem
Props
ToggleGroupRootProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
defaultValueInitial value used when the component owns its state.
deselectableWhether selecting the current item again clears it.
disabledWhether interaction is unavailable.
disabledItemsItem values excluded from focus and selection.
formID of the native form associated with the control.
itemsOrdered item values managed by the component.
labelAccessible name announced for the control.
modelValueCurrent value when state is controlled by the parent.
multipleWhether more than one value can be selected.
nameName used for native form submission.
orientationAxis used for layout and keyboard movement.
readonlyWhether the value can be inspected but not changed.
requiredWhether the control must contain a valid value before submission.
ToggleGroupItemProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
disabledWhether interaction is unavailable.
valueCurrent value exposed by this contract.
Slots
ToggleGroupRootSlotProps
disabledWhether interaction is unavailable.
highlightedValueValue currently highlighted for interaction.
readonlyWhether the value can be inspected but not changed.
valueCurrent value exposed by this contract.
ToggleGroupItemSlotProps
disabledWhether interaction is unavailable.
highlightedWhether this item is highlighted for interaction.
pressedWhether the toggle is pressed.
readonlyWhether the value can be inspected but not changed.
valueCurrent value exposed by this contract.
Events
ToggleGroupRoot
highlightEmitted when the highlighted item changes.
update:modelValueEmitted when the component requests a new controlled value.
Other types
ToggleGroupValueChangeHandler
type ToggleGroupValueChangeHandler = (value: readonly string[]) => voidToggleGroupHighlightHandler
type ToggleGroupHighlightHandler = (value: string | null) => voidParts
Shared scope: [data-scope="toggle-group"]. Combine it with a part selector to keep styles local to this component.
| Part | Selector | Role | Extra attributes |
|---|---|---|---|
root | [data-part="root"] | Defines the component boundary and owns its composed parts. | — |
item | [data-part="item"] | Represents one selectable or actionable item. | — |
Keyboard interaction
| Key | Behavior |
|---|---|
| Arrow keys | Move the active option in the visible orientation. |
| Home / End | Move to the first or last eligible option. |
| Enter / Space | Select or activate the current option. |
| Printable text | Move to the next matching option when typeahead is available. |
Accessibility
The labeled group exposes each item as a pressed button and uses one roving tab stop.
See the corresponding WAI-ARIA pattern for the host accessibility contract.
