Overview
Toggle Group provides a set of toggle buttons that work together. It supports both single and multiple selection modes, making it useful for toolbar buttons, formatting options, or filter selections.Features
- Supports single or multiple selection
- Can be controlled or uncontrolled
- Full keyboard navigation with roving focus
- Supports horizontal/vertical orientation
- Accessible by default with proper ARIA attributes
Installation
Anatomy
API Reference
Root
Contains all the toggle group items.Determines whether a single or multiple items can be pressed at a time.
type="single":
The controlled value of the pressed item.
The value of the item to show as pressed when initially rendered (uncontrolled).
Event handler called when the pressed state changes.
type="multiple":
The controlled value of the pressed items.
The values of the items to show as pressed when initially rendered (uncontrolled).
Event handler called when the pressed state changes.
When true, prevents the user from interacting with the toggle group and all its items.
When false, navigating through the items using arrow keys will be disabled.
The orientation of the component.
The reading direction of the toggle group. If omitted, inherits from the parent.
When loop and rovingFocus are true, keyboard navigation will loop from last item to first, and vice versa.
Change the default rendered element for the one passed as a child.
Item
An item in the toggle group.A unique value for the item.
When true, prevents the user from interacting with the item.
Change the default rendered element for the one passed as a child.
Example
Accessibility
Uses roving tabindex to manage focus movement among items.
Keyboard Interactions
- Tab - Moves focus to either the pressed item or the first item in the group.
- Space - Activates/deactivates the item.
- Enter - Activates/deactivates the item.
- ArrowDown - Moves focus to the next item in the group (vertical orientation).
- ArrowRight - Moves focus to the next item in the group (horizontal orientation).
- ArrowUp - Moves focus to the previous item in the group (vertical orientation).
- ArrowLeft - Moves focus to the previous item in the group (horizontal orientation).
- Home - Moves focus to the first item.
- End - Moves focus to the last item.
Data Attributes
Root[data-orientation]- “horizontal” or “vertical”
[data-state]- “on” or “off”[data-disabled]- Present when disabled[data-orientation]- “horizontal” or “vertical”