Segmented Control
ProNewOne choice out of a few, with a thumb that slides to the selected segment using a transform alone.
Installation
pnpm dlx shadcn@latest add @viewport/segmented-control
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| options* | SegmentedOption[]The choices, in order. Every segment gets the width of the widest one. | — |
| label* | stringAccessible name for the group, e.g. "View". | — |
| value | string | — |
| defaultValue | string | — |
| onValueChange | (value: string) => void | — |
| size | "sm" | "md" | "md" |
| fullWidth | booleanStretch to the width of the container. | false |
| name | stringSubmits the value with a form. | — |
| disabled | boolean | — |
| className | string | — |
Accessibility
- A radio group: arrow keys select, and the group has a name.
- The thumb is in place before hydration and is mirrored in right-to-left layouts.
- Works inside a form through `name`.
- Respects prefers-reduced-motion.