Toggle Group

Web/Mobile

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

Installation

pnpm dlx cubix-ui@latest add toggle-group --base aria

Usage

Import
import { ToggleGroup, ToggleGroupItem } from "@/components/cubix/toggle-group"
Example
<ToggleGroup>
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
  <ToggleGroupItem value="c">C</ToggleGroupItem>
</ToggleGroup>

Composition

Use the following composition to build a ToggleGroup:

 
ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem

Outline

Use variant="outline" for an outline style.

Segmented

Use variant="segmented" for a single-choice switch on a muted track, where the selected item is raised onto a card surface.

Size

Use the size prop to change the size of the toggle group.

Spacing

Use spacing to control the gap between items. Default is 2. Use spacing=0 for connected items.

Vertical

Use orientation="vertical" for vertical toggle groups.

Disabled

Custom

A custom toggle group example.

Use font-normal to set the font weight.

RTL

Wrap the group in a container with dir="rtl" to mirror direction.

API Reference

See also the Base UI Toggle Group documentation for primitive props.

ToggleGroup

PropTypeDefaultDescription
variant"default" | "outline" | "segmented""default"Visual style applied to all items unless overridden.
size"default" | "sm" | "lg""default"Size applied to all items unless overridden.
spacingnumber2Gap between items. Use 0 for connected items with shared borders.
orientation"horizontal" | "vertical""horizontal"Layout orientation of the group.
multiplebooleanfalseWhen true, more than one item can be pressed (Base UI). Radix uses type="multiple".
valuestring[]-Controlled pressed values.
defaultValuestring[]-Uncontrolled initial pressed values.
onValueChange(value: string[]) => void-Called when the pressed values change.
disabledbooleanfalseWhen true, interaction is disabled for the group.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

ToggleGroupItem

PropTypeDefaultDescription
valuestring-Unique value for this item within the group.
variant"default" | "outline" | "segmented"-Overrides the group variant for this item.
size"default" | "sm" | "lg"-Overrides the group size for this item.
disabledbooleanfalseWhen true, this item cannot be pressed.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).