ToggleGroup

A compact group of toggle buttons for independent or optional pressed states.

Preview#

import { ToggleGroup, ToggleGroupItem, ToggleGroupLabel } from "raft-ui";

<ToggleGroup multiple defaultValue={["bold"]} aria-label="Text formatting">
  <ToggleGroupItem value="bold">
    <ToggleGroupLabel>Bold</ToggleGroupLabel>
  </ToggleGroupItem>
</ToggleGroup>

Use ToggleGroup when an item may be toggled off. Use SegmentedControl for a persistent one-of-many value that changes a view, filter, or mode.

One or none#

Vertical orientation#

Disabled item#

Disabled group#

API#WIP

PropTypeDefaultDescription
valuereadonly T[]Pressed item values for controlled use.
defaultValuereadonly T[]Initially pressed item values for uncontrolled use.
onValueChange(value: T[], eventDetails: ToggleGroup.ChangeEventDetails) => voidCalled when the pressed item collection changes.
multiplebooleanfalseAllows more than one item to stay pressed.
orientation"horizontal" | "vertical""horizontal"Controls visual layout and arrow-key navigation.
loopFocusbooleantrueWraps roving keyboard focus at either end of the group.
disabledbooleanfalseDisables every item in the group.
...propsBase UI ToggleGroup.Props<T>Native div attributes, render substitution, styling, and ARIA labeling.
PropTypeDefaultDescription
valueTRequired unique value tracked in the parent group's pressed collection.
disabledbooleanfalseDisables this item without disabling its siblings.
onPressedChange(pressed: boolean, eventDetails: Toggle.ChangeEventDetails) => voidPer-item callback fired when this item's pressed state changes, before the group's onValueChange. Use eventDetails.cancel() to reject a single item's press.
...propsToggleGroupItemProps<T>Base UI Toggle props without standalone pressed/defaultPressed state, plus a required value.
PropTypeDefaultDescription
...propsComponentPropsWithRef<"span">Visible item label with truncation and native span attributes.