Segmented control
FreeOne choice from a few visible options. A single elevated indicator glides to the selection, and arrow keys move it.
Revenue
Reporting period for the overview.
Installation #
pnpm dlx shadcn@latest add https://caliperui.site/r/segmented-control.json
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage #
Use it for two to five short, mutually exclusive options that change a view immediately: a reporting period, a layout, a unit.
It is a radiogroup. Give it a label, keep option labels short, and handle the change in onValueChange.
For more than five options or long labels, use a select or radio cards instead.
import { SegmentedControl } from "@/components/ui/segmented-control" const periods = [ { value: "week", label: "Week" }, { value: "month", label: "Month" }, { value: "quarter", label: "Quarter" }, ] export function ReportPeriod({ value, onChange }) { return ( <SegmentedControl label="Reporting period" value={value} onValueChange={onChange} options={periods} /> ) }
Examples #
Two options
A binary view switch such as List and Board.
Five options
The practical maximum before labels crowd on a phone.
API reference #
Controlled. All props are required except className.
Accessibility #
Rendered as role="radiogroup" with role="radio" options and a roving tab index, so Tab enters once and arrows move the selection.
Motion #
One raised plate travels to the chosen option on the settle curve and stretches 7% toward it mid-flight. The value and labels change at once. Under reduced motion the plate jumps and does not stretch.