Skip to main content

Toggle Group

View as Markdown

A set of toggle buttons where one or several can be pressed.

<primitives:toggleGroup.root>
    <primitives:toggleGroup.item />
</primitives:toggleGroup.root>
typo3 ui:add toggle-group

Read more about installing Components and Primitives.

Allow several items to be pressed at the same time.

Stack the items vertically. The arrow keys follow the orientation.

Disable the whole group, or single items. A disabled group always wins over an item, an item can not opt out of it.

Keep one item always pressed. This has no effect with multiple.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Provides the shared state and wraps the items. Renders a <div> element with role="group".

NameDescriptionRequiredDefault
defaultValuestring[]
The initial value of the pressed items when rendered. Use when you don't need to control the value of the toggle group.
No
-
disabledboolean
Whether all items of the toggle group are disabled.
No
-
multipleboolean
Whether multiple items can be pressed at the same time.
No
false
deselectableboolean
Whether the pressed item can be deselected again. Ignored when `multiple` is `true`.
No
true
loopFocusboolean
Whether the keyboard navigation loops from the last item to the first, and vice versa.
No
true
rovingFocusboolean
Whether the items use a roving tabindex, so the whole group is a single tab stop and the arrow keys move the focus.
No
true
orientationEnum\Orientation
The orientation of the toggle group.
No
Horizontal
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-toggle-group-root<uid>
data-disabledPresent when disabled
data-multiple
data-orientationThe orientation of the toggle-group

A toggle button of the group. Renders a <button> element.

NameDescriptionRequiredDefault
valuestring
The value of the toggle group item.
Yes
-
disabledboolean
Whether the item is disabled. An item of a disabled group is always disabled.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-toggle-group-item<uid>
data-pressedPresent when pressed
data-disabledPresent when disabled
data-orientationThe orientation of the item
NameTypeDescription
valuestring[]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
KeyDescription
TabMoves focus to either the pressed item or the first item in the group.
SpaceActivates/deactivates the item.
EnterActivates/deactivates the item.
ArrowDownMoves focus to the next item in the group.
ArrowRightMoves focus to the next item in the group.
ArrowUpMoves focus to the previous item in the group.
ArrowLeftMoves focus to the previous item in the group.
HomeMoves focus to the first item.
EndMoves focus to the last item.