Installation
npx logic2b@next add toggle-groupUsage
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
<ToggleGroup type="multiple">
<ToggleGroupItem value="bold" aria-label="Toggle bold">
<BoldIcon />
</ToggleGroupItem>
</ToggleGroup>
Usage notes
Built on Radix ToggleGroup. The group’s variant and size are shared with
every ToggleGroupItem through context.
Examples
Single selection
Sizes
Accessibility
- With
type="single"items behave as a radio group;Arrowkeys move selection between them. - With
type="multiple"each item toggles independently and exposesaria-pressed. Tabmoves focus into the group, thenArrowkeys move between items; icon-only items need anaria-label.
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<ToggleGroup
type="single"
defaultValue="center"
variant="outline"
size="default"
aria-label="Text alignment"
>
<ToggleGroupItem
value="left"
aria-label="Align left"
>Left</ToggleGroupItem>
<ToggleGroupItem
value="center"
aria-label="Align center"
>Center</ToggleGroupItem>
<ToggleGroupItem
value="right"
aria-label="Align right"
>Right</ToggleGroupItem>
</ToggleGroup>API reference
Generated from the public TypeScript exports in src/ui/toggle-group.tsx.
ToggleGroup
ComponentProps: React.ComponentProps<typeof ToggleGroupPrimitive.Root> & VariantProps<typeof toggleVariants>| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | null | "default" | "outline" | No | — | — |
size | null | "default" | "sm" | "lg" | No | — | — |
ToggleGroupItem
ComponentProps: React.ComponentProps<typeof ToggleGroupPrimitive.Item> & VariantProps<typeof toggleVariants>| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
variant | null | "default" | "outline" | No | — | — |
size | null | "default" | "sm" | "lg" | No | — | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for toggle-group.
- Support
- Primitive-managed
- Pattern
- toggle group
- Radix Toggle Group
| Keys | Behavior |
|---|---|
| ArrowUp ArrowDown ArrowLeft ArrowRight | Move within the composite control. |
| Enter Space | Activate the focused control. |
Built-in semantics
- Uses roving focus and pressed/selected state for single or multiple selection.
Consumer responsibilities
- Label the group and every icon-only item.