Toggle Group
A set of two-state buttons that can be toggled on or off.
Anatomy
<ToggleGroup.Root>
<ToggleGroup.Item />
</ToggleGroup.Root>
Examples
Controlled
Pass value and update it in onValueChange.
Root Provider
Use RootProvider with the useToggleGroup hook to access the state and methods from outside the component.
Multiple
Set multiple to allow selecting more than one item.
With Tooltip
Compose an item with Tooltip.Trigger via asChild. Match ids.item and ids.trigger so they share one element and
tab stop.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
defaultValue | string[]The initial selected value of the toggle group when rendered. Use when you don't need to control the selected value of the toggle group. | |
deselectable | true | booleanWhether the last pressed item can be unpressed, leaving the selection empty. |
disabled | booleanWhether the toggle is disabled. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the toggle. Useful for composition. | |
loopFocus | true | booleanWhether to loop focus inside the toggle group. |
multiple | booleanWhether to allow multiple toggles to be selected. | |
onValueChange | (details: ValueChangeDetails) => voidFunction to call when the toggle is clicked. | |
orientation | 'horizontal' | OrientationThe orientation of the toggle group. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ToggleGroupRootState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
rovingFocus | true | booleanWhether to use roving tab index to manage focus. |
value | string[]The controlled selected value of the toggle group. |
| Attribute | Description |
|---|---|
[data-toggle-group-root] | <uid> |
[data-disabled] | Present when disabled |
[data-multiple] | |
[data-orientation] | The orientation of the toggle-group |
Item
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
value | string | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
disabled | boolean | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ToggleGroupItemState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-toggle-group-item] | <uid> |
[data-pressed] | Present when pressed |
[data-disabled] | Present when disabled |
[data-orientation] | The orientation of the item |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UseToggleGroupReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<ToggleGroupRootProviderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Context
API
| Property | Type |
|---|---|
value | string[]The value of the toggle group. |
setValue | (value: string[]) => voidSets the value of the toggle group. |
getItemState | (props: ItemProps) => ItemStateReturns the state of the toggle item. |
getRootState | () => RootStateReturns the state of the toggle group |
Accessibility
Keyboard Support
| Key | Description |
|---|---|
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. |
ArrowRight | Moves focus to the next item in the group. |
ArrowUp | Moves focus to the previous item in the group. |
ArrowLeft | Moves focus to the previous item in the group. |
Home | Moves focus to the first item. |
End | Moves focus to the last item. |