Components
Toggle Group
A set of toggles with shared single or multiple selection.
Loading...
Installation
npx shadcn@latest add @fujin/toggle-groupUsage
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"<ToggleGroup
aria-label="Text alignment"
defaultValue={["left"]}
variant="outline"
>
<ToggleGroupItem value="left" aria-label="Align left">
<AlignLeftIcon />
</ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center">
<AlignCenterIcon />
</ToggleGroupItem>
</ToggleGroup>What's different from shadcn/ui
- The value is always an array. Base UI has no
type="single" | "multiple"prop: single selection is the default and still usesvalue={["left"]}; passmultipleto allow several pressed items.onValueChangereceivesstring[]either way. - In single mode, clicking the pressed item unpresses it (the value becomes
[]). To require a selection, ignore empty changes inonValueChange- see the demo. variantandsizeon the group flow to every item via context, but an item's ownvariant/sizewins.spacing={0}(the default) joins items into one segmented control; any other number is a gap in Tailwind spacing units.orientation="vertical"stacks the items and switches arrow-key navigation to Up/Down.
API Reference
Prop
Type
Every other prop is forwarded to the Base UI ToggleGroup; items forward to Toggle.