SegmentedControl

Pick one of 2–4 short options, all visible.

$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/segmented-control.json

Fill (forms)

Equal options across the parent. Track 44, option 38, inset 3; the selected option is white with shadow-button.

Hug (toolbars)

Options fit their label; an optional count follows the label in grey.

Disabled

A single option or the whole control at 60 %.

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

DoShort, parallel labels"Tahunan · Penting · Sakit": one word each, the same kind of thing, all visible at once.
Don'tFive 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.

terminal
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/segmented-control.json

API

import { SegmentedControl } from "@/components/ui/segmented-control"
PropTypeDefaultDescription
options{ value: string; label: ReactNode; count?: number; disabled?: boolean }[]–2–4 options. Nothing else exists.
value · onValueChangestring · (value: string) => void–Controlled. One option is always selected.
defaultValuestring–Uncontrolled start value.
width"fill" | "hug""fill"fill in forms, hug in toolbars.
disabledbooleanfalseWhole control at 60 %.
aria-labelstring–Required when no visible label names the group.