SegmentedControl
Pick one of 2–4 short options, all visible.
$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/segmented-control.jsonFill (forms)
Hug (toolbars)
Disabled
When to use
- Pick one of 2–4 short options that should all stay visible: Jenis cuti (Tahunan · Penting · Sakit).
- Switch the view of the same data: Bagan (Kanvas · Kolom).
- Filter a list in a toolbar with counts: Semua 48 · Percobaan 3 · Kontrak 4.
When not to use
- 5 or more options → Select.
- Options with a description line → RadioGroup / RadioCard.
- Moving between unrelated screens → the rail (AppShell). Never page navigation.
- A setting that applies at once (on/off) → Switch.
Do and don't
Short, parallel labels"Tahunan · Penting · Sakit": one word each, the same kind of thing, all visible at once.
Five options or long labelsLabels wrap and the track grows. Use a Select for 5+ options, a RadioGroup when options need a description.
Installation
Add SegmentedControl with the shadcn CLI (your project needs a components.json and the MaHR theme: https://mahrdesign.faizintifada.com/r/theme.json), or copy the files by hand.
API
import { SegmentedControl } from "@/components/ui/segmented-control"| Prop | Type | Default | Description |
|---|---|---|---|
options | { value: string; label: ReactNode; count?: number; disabled?: boolean }[] | – | 2–4 options. Nothing else exists. |
value · onValueChange | string · (value: string) => void | – | Controlled. One option is always selected. |
defaultValue | string | – | Uncontrolled start value. |
width | "fill" | "hug" | "fill" | fill in forms, hug in toolbars. |
disabled | boolean | false | Whole control at 60 %. |
aria-label | string | – | Required when no visible label names the group. |