Toggle Group
A set of toggles that behaves like a toolbar: several can be on at once (type="multiple") or at most one (type="single"). The group is one tab stop; arrow keys move between items.
Installation
Add Toggle Group to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
ToggleGroup.tsxToggle.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-toggle@radix-ui/react-toggle-groupclass-variance-authorityif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Add the Toggle component
ToggleGroup imports ./Toggle, so add this file next to it
Create or update your ToggleGroup component
Copy this code to create your ToggleGroup component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Single Selection
type="single" allows at most one pressed item. Pressing it again clears the value; ignore empty values to always keep one.
Alignment: left
Vertical
orientation="vertical" stacks the items; use ArrowUp/ArrowDown.
Toggle Group vs Segmented Control
- Toggle Group: toolbar-style toggles that change something (formatting, filters). Items can be independent (multiple) or exclusive (single), and the group can end up with nothing pressed.
- Segmented Control: choose exactly one mode or view (List / Board / Calendar). One option is always selected.
Accessibility
- The group has
role="group"; name it witharia-label. - Multiple: each item is a button with
aria-pressed. Single: items are exposed as radio buttons witharia-checked. - One tab stop for the whole group (roving focus): arrow keys move between items, Home/End jump to the ends; disabled items are skipped.
- Icon-only items need an aria-label; the label does not change with the state.
API Reference
Built on Radix Toggle Group. Import with import * as ToggleGroup from "@/components/ui/ToggleGroup".
ToggleGroup.Root
See Radix UI docs for base props.
| Prop | Type | Default | Description |
|---|---|---|---|
type | "single""multiple" | "-" | Required. Exclusive or independent items. |
value / defaultValue | "string | string[]" | "undefined" | Pressed value(s); a string for single, an array for multiple. |
onValueChange | "(value) => void" | "undefined" | Called with the new value(s). |
orientation | "horizontal""vertical" | "horizontal" | Layout and arrow-key direction. |
rovingFocus | "boolean" | "true" | One tab stop with arrow-key navigation. |
loop | "boolean" | "true" | Arrow keys wrap around. |
disabled | "boolean" | "false" | Disables every item. |
variant | "ghost""stroke" | "ghost" | Passed to every item. |
size | "xs""sm""md""lg" | "md" | Passed to every item. |
className | "string" | "undefined" | Additional classes, merged last. |
ToggleGroup.Item
See Radix UI docs for base props.
| Prop | Type | Default | Description |
|---|---|---|---|
value | "string" | "-" | Required. The item's value. |
disabled | "boolean" | "false" | Skipped by the keyboard. |
variant / size | "-" | "group's" | Override the group's treatment for one item. |
className | "string" | "undefined" | Additional classes, merged last. |