Toggle Group
Headless group of toggle buttons with roving focus and single or multiple selection.
Toggle Group in motion
When to Use
Use ToggleGroup when several related pressed buttons should act as one
keyboard group, such as text alignment or formatting choices. Use RadioGroup
when single-selection choices are form answers, and individual Toggle parts
when the buttons are unrelated.
Features
The behavior Atom owns before your product adds appearance.
- Supports single and multiple selection.
- Can be controlled or uncontrolled.
- Supports horizontal and vertical arrow-key navigation.
- Mirrors horizontal Arrow keys in RTL through
Direction.Provider. - Supports optional looping focus.
- Registers items in DOM order.
- Exposes selected, disabled, orientation, and value data attributes.
Import
Anatomy
API Reference
Root
Owns single or multiple selection and roving focus for every Item in the group.
| Prop | Type | Default |
|---|---|---|
type | "single" | "multiple" | "single" |
value | string | string[] | - |
defaultValue | string | string[] | [] |
onValueChange | (value: string | string[]) => void | - |
disabled | boolean | false |
orientation | "horizontal" | "vertical" | "horizontal" |
loop | boolean | true |
ariaLabel | string | - |
asChild | boolean | false |
render | RenderProp | - |
| ARIA attribute | Values |
|---|---|
role | "group" |
aria-label | Value from ariaLabel when provided |
aria-disabled | true when disabled |
| Data attribute | Values |
|---|---|
[data-slot] | "toggle-group" |
[data-orientation] | "horizontal" | "vertical" |
[data-disabled] | Present when disabled |
Item
Renders one roving-focus pressed button and reads group selection and disabled state while allowing a local disabled override.
| Prop | Type | Default |
|---|---|---|
value | string | required |
disabled | boolean | false |
ariaLabel | string | - |
asChild | boolean | false |
render | RenderProp | - |
| ARIA attribute | Values |
|---|---|
role | "button" for a custom non-native element |
aria-pressed | Current selected state |
aria-label | Value from ariaLabel when provided |
aria-disabled | true when the Item or Root is disabled |
| Data attribute | Values |
|---|---|
[data-slot] | "toggle-group-item" |
[data-state] | "on" | "off" |
[data-value] | Item value |
[data-disabled] | Present when disabled |
Advanced compound parts can read useToggleGroupContext or use the public
ToggleGroupContextProvider.
Examples
Single Selection
Multiple Selection
Accessibility
ToggleGroup composes the WAI-ARIA toggle-button pattern inside a named group.
Root is one roving Tab stop and Items expose aria-pressed.
| Key | Description |
|---|---|
ArrowRight | Moves focus to the next item when horizontal LTR, previous in RTL. |
ArrowLeft | Moves focus to the previous item when horizontal LTR, next in RTL. |
ArrowDown | Moves focus to the next item when vertical. |
ArrowUp | Moves focus to the previous item when vertical. |
Home | Moves focus to the first enabled item. |
End | Moves focus to the last enabled item. |
Enter / Space | Toggles the focused item. |
Changelog
Unreleased
0.24.0
- Added public Agent Knowledge for component selection, required composition, recurring mistakes, and validation.
0.2.0
- Fixed disabled native
ToggleGroup.Itembuttons so they rely on the nativedisabledattribute without adding redundantaria-disabled; non-native composed items still receivearia-disabled. - Fixed disabled
ToggleGroup.Rootsemantics so the group exposesaria-disabledalongsidedata-disabled. - Fixed
ToggleGroup.Rootsingle mode so changing from multiple selected values exposes only one pressed item. - Fixed
ToggleGroup.Itemroving focus for composed non-native items so disabled items are skipped consistently inasChildandrenderpaths. - Fixed
ToggleGroup.Itemcollection registration so changingasChildorrendercomposition refreshes the DOM node used for arrow navigation. - Fixed
ToggleGroup.Roothorizontal arrow navigation so it mirrors ArrowLeft/ArrowRight when used underDirection.Provider dir="rtl".
0.1.0
- Initial Atom release.