Skip to content

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.

Multiple

Select several values independently without collapsing the existing selection.

Select several values independently without collapsing the existing selection.

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.

API

Vue package: @sectile/vue/toggle-group

Components
  • ToggleGroupRoot
  • ToggleGroupItem

Props

ToggleGroupRootProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

defaultValue

Initial value used when the component owns its state.

deselectable

Whether selecting the current item again clears it.

disabled

Whether interaction is unavailable.

disabledItems

Item values excluded from focus and selection.

form

ID of the native form associated with the control.

items

Ordered item values managed by the component.

label

Accessible name announced for the control.

modelValue

Current value when state is controlled by the parent.

multiple

Whether more than one value can be selected.

name

Name used for native form submission.

orientation

Axis used for layout and keyboard movement.

readonly

Whether the value can be inspected but not changed.

required

Whether the control must contain a valid value before submission.

ToggleGroupItemProps

as

Element or component rendered for this part.

asChild

Whether to merge this part into its single child instead of rendering a wrapper.

disabled

Whether interaction is unavailable.

value

Current value exposed by this contract.

Slots

ToggleGroupRootSlotProps

disabled

Whether interaction is unavailable.

highlightedValue

Value currently highlighted for interaction.

readonly

Whether the value can be inspected but not changed.

value

Current value exposed by this contract.

ToggleGroupItemSlotProps

disabled

Whether interaction is unavailable.

highlighted

Whether this item is highlighted for interaction.

pressed

Whether the toggle is pressed.

readonly

Whether the value can be inspected but not changed.

value

Current value exposed by this contract.

Events

ToggleGroupRoot

highlight

Emitted when the highlighted item changes.

update:modelValue

Emitted when the component requests a new controlled value.

Other types

ToggleGroupValueChangeHandler

ts
type ToggleGroupValueChangeHandler = (value: readonly string[]) => void

ToggleGroupHighlightHandler

ts
type ToggleGroupHighlightHandler = (value: string | null) => void

Parts

Shared scope: [data-scope="toggle-group"]. Combine it with a part selector to keep styles local to this component.

PartSelectorRoleExtra 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

KeyBehavior
Arrow keysMove the active option in the visible orientation.
Home / EndMove to the first or last eligible option.
Enter / SpaceSelect or activate the current option.
Printable textMove 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.

Released under the MIT License.