Toggle group
npx shadcn add @klarhimmel/toggle-groupCopy for AIExamples
Single
Multiple
View
DetailsAbout, usage, props and more
A row of toggles that belong together: pick one, or any number.
When to use
Use for
View switches, alignment and formatting tools that belong together.
Not for
Moving between pages or panels. Use Tabs.
Pairs with
Icons, Tooltip.
Preview
Aligned left
Import
Import
- Files
- toggle-group.tsx, in components/klarhimmel/ui/. With it: theme, toggle, utils.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
ToggleGroup.type | 'single' | required | Required. Single is a radio group (press the chosen one again to clear it); multiple is a group of pressed buttons. |
ToggleGroup.value | string | - | A string when single, a list when multiple. |
ToggleGroup.defaultValue | string | - | A string when single, a list when multiple. |
ToggleGroup.onValueChange | (value: string) => void | - | A string when single, a list when multiple. |
ToggleGroup.label | string | required | Required: names the group ("Text alignment"). |
ToggleGroup.variant | 'segmented' | 'chips' | - | 'segmented' (default): buttons on one quiet track, for a view or an alignment. 'chips': separate pills that wrap, for a filter or a set of options (room type, amenities); an on chip is the soft accent with an accent ring, in light and dark alike. |
ToggleGroup.className | string | - | Extra classes, merged after the component's own. |
ToggleGroup.children | ReactNode | required | |
ToggleGroupItem.value | string | required | A string when single, a list when multiple. |
ToggleGroupItem.disabled | boolean | - | |
ToggleGroupItem.children | ReactNode | required | |
ToggleGroupItem.className | string | - | Extra classes, merged after the component's own. |
ToggleGroupItem.aria-label | string | - |
Accessibility
| Key | Does |
|---|---|
Tab | Enters and leaves the group as one stop (single mode) |
Right / Left | Moves focus to the next or previous button, wrapping |
Home / End | First or last button |
Enter / Space | Presses the focused button |
Single is a radio group; pressing the chosen button again clears it. Multiple is a group of pressed buttons.
Accessibility