A row of options where one is picked, like a view switcher. The highlight slides to the choice.
$ pnpm dlx shadcn@latest add https://dashral.com/r/segmented-control.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/segmented-control.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/segmented-controlUsage
import { SegmentedControl } from "@/components/dashral/segmented-control"
<SegmentedControl
aria-label="Calendar view"
defaultValue="week"
options={[
{ value: "day", label: "Day" },
{ value: "week", label: "Week" },
{ value: "month", label: "Month" },
]}
/>Examples
API reference
SegmentedControl
Also takes every prop of Radix Radio Group(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
value / defaultValue | string | — |
onValueChange | (value: string) => voidCalled with the new value. | — |
options | (string | { value; label?; icon?; disabled?; "aria-label"? })[]The segments. An icon-only one needs an aria-label. | — |
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
classNames | { root, label, description, error, group, item }Classes for each part. | — |
aria-label | stringWithout a label: names the choice, e.g. “Calendar view”. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Move into the control |
| ←or→ | Move and pick |
Accessibility
- A radio group, so screen readers say “2 of 4, selected”; label names it through aria-labelledby. For switching panels of content, use Tabs.
Motion
- The highlight glides to the picked option (--duration-considered, --ease-standard); it just moves with reduced motion.