Toggle Group
Group related pressed-state buttons.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/toggle-groupComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/inputField is installed with Input.
Usage
import {
ToggleGroup,
ToggleGroupItem,
} from "@/siteplane/components/toggle-group";
<ToggleGroup aria-label="View" defaultValue={["grid"]}>
<ToggleGroupItem value="grid">Grid</ToggleGroupItem>
<ToggleGroupItem value="list">List</ToggleGroupItem>
</ToggleGroup>;Composition
ToggleGroup
├── ToggleGroupItem
├── ToggleGroupSeparator
└── ToggleGroupItemMultiple selection
Set multiple to allow several pressed items. value is always an array, in single and multiple mode.
With label
Name the group with a visible FieldLabel and point aria-labelledby at it. To keep one option selected, ignore empty values in onValueChange.
With separators
Place a ToggleGroupSeparator between sets of related items. It is vertical by default; in a vertical group, set orientation="horizontal". Outline groups already draw a divider between every item.
Vertical
Set orientation="vertical" to stack the items; arrow-key navigation follows the orientation.
Sizes
Set size (and variant) on the group; every item inherits it.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
variant | default | outline | default | Item surface. |
size | sm | md | lg | xl | provider / lg | Item size. |
multiple | boolean | false | Allow multiple pressed items. |
orientation | horizontal | vertical | horizontal | Layout and keyboard orientation. |
width | auto | full | auto | Fit or full width. |
wrap | boolean | false | Allow wrapping. |
value / default | string[] | uncontrolled | Selection. |
on | (values, eventDetails) => void | unset | Selection callback. |
Toggle | boolean | false | Flex-grow item. |
Toggle | label | unset | Cap at max-w-40 and truncate label. |
Toggle | default | comfortable | default | Padding. |
Toggle | horizontal | vertical | vertical | Divider direction. |
Items accept Base UI Toggle props including value and disabled and take the
group's size and variant. Separator accepts Separator props and draws the
divider between joined items. ToggleGroupPrimitive exposes the Base UI namespace. ToggleGroupContext
defaults to single false, inherited size and variant default. Other root props and
keyboard behavior follow Base UI Toggle
Group.
Usage notes
Tab enters the group; arrow keys move among items. Unlike RadioGroup, a single selected item can be cleared. Use Tabs for associated content panels.