Installation
$ pnpm dlx shadcn@latest add @synccn/toggle-groupFirst time in this project? Connect synccn with one command.
Usage
import { ToggleGroup } from "@/components/ui/toggle-group";<ToggleGroup options={ranges} />API reference
Generated from the component's TypeScript types, so it always matches the code.
ToggleGroup
Segmented control. type "single" -> value is a string, type "multiple" -> value is an array. options: [{ value, label?, icon?, "aria-label"? }]
PropTypeDescription
- type
"single" | "multiple"Default
"single"One choice (string value) or several (array value).
- value
string | string[]Controlled value: a string, or string[] when type is multiple.
- defaultValue
string | string[]Initial value when uncontrolled.
- onValueChange
((value: string) => void) | ((value: string[]) => void)Called with the new value.
- optionsrequired
ToggleGroupOption[]Segments.
- size
"sm" | "default"Default
"default"Segment height.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
Keyboard
- TabMove between segments
- SpaceorEnterChoose the focused segment
Accessibility
- Icon-only segments need an aria-label in their option.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: type
- ARIA attributes: aria-checked, aria-label, aria-pressed
- Shows a visible focus ring for keyboard users
More inputs
ButtonSeven variants, four sizes and a built-in loading state.InputText field with optional leading icon and invalid state.TextareaMulti-line field that grows with its content and counts characters.CheckboxChecked, unchecked and indeterminate, with label and description.SwitchToggle with a springy thumb in three sizes.Radio GroupPick one option, shown as dots or as selectable cards.