Captain UI

Segmented control

A raised thumb in a well. Tap a segment and it springs over, or grab the thumb and slide it: it squishes as you press and a flick decides where it lands.

npx shadcn@latest add https://captain-ui.vercel.app/r/segmented.json

$240 per year

Billed $240 once, two months free

Usage

import { Segmented } from "@/components/ui/segmented"

<Segmented
  aria-label="Billing period"
  defaultValue="yearly"
  options={[{ value: "monthly", label: "Monthly" }, { value: "yearly", label: "Yearly" }]}
/>

Props

PropTypeDefaultWhat it does
options{ value: string; label: ReactNode; disabled?: boolean }[]The segments, all the same width.
valuestringControlled value.
defaultValuestringoptions[0].valueInitial value when uncontrolled.
onValueChange(value: string) => voidCalled on tap, drag release or arrow key.
aria-labelstringNames the group. Required.
size"sm" | "md""md"32 or 36px tall.
disabledbooleanDims and ignores input.

Keyboard

← →
Previous / next segment
Home / End
First / last segment

Accessibility

  • role=radiogroup with a role=radio per segment and aria-checked.
  • Roving tabindex: Tab lands on the selected segment, arrows move and select.
  • Dragging is optional: tap and keyboard do the same thing.