Toggle Group

A set of two-state buttons that can be toggled on or off.

Loading...

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.

AttributeDefaultType
asChild
boolean

Use 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.

deselectabletrue
boolean

Whether the last pressed item can be unpressed, leaving the selection empty.

disabled
boolean

Whether the toggle is disabled.

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the elements in the toggle. Useful for composition.

loopFocustrue
boolean

Whether to loop focus inside the toggle group.

multiple
boolean

Whether to allow multiple toggles to be selected.

onValueChange
(details: ValueChangeDetails) => void

Function to call when the toggle is clicked.

orientation'horizontal'
Orientation

The 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.

rovingFocustrue
boolean

Whether to use roving tab index to manage focus.

value
string[]

The controlled selected value of the toggle group.

AttributeDescription
[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.

AttributeDefaultType
value
string

asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
value
UseToggleGroupReturn

asChild
boolean

Use 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

PropertyType
value
string[]

The value of the toggle group.

setValue
(value: string[]) => void

Sets the value of the toggle group.

getItemState
(props: ItemProps) => ItemState

Returns the state of the toggle item.

getRootState
() => RootState

Returns the state of the toggle group

Accessibility

Keyboard Support

KeyDescription
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.