- Add the registry
- Add toggle-group
Usage
multiple lets any number of items be pressed. The value is always an array. Give the group an
aria-label or aria-labelledby, and give icon-only items their own labels.
When exactly one option must be selected, use a Segmented Control.
Inside a Toolbar, use ToolbarToggleGroup.
Composition
Examples
Single
Without multiple, only one item can be pressed at a time.
Joined
Set spacing={0} to join the items into one control.
In a form
Give a Field or the group a name, and each pressed item's value submits under it, so
formData.getAll(name) returns them all, and Form's onFormSubmit gets them as an array. Pass
form with a form's id when the group sits outside it. With required, the form won't submit
until an item is pressed, which fails as valueMissing. A form reset brings back defaultValue.
Inside a Field, a FieldLabel names the group, and the group reads out the field's
FieldDescription and FieldError.
Props
size on ToggleGroup applies to every item.
The tables leave out className, style and render. Parts built on Base UI take them as its styling and composition guides describe.