Segmented control preview

Segmented control

Switch between two to six options – a raised pill or underline that glides, stretches a little and can be dragged across, with icons, counts and badges

  • Group
    Tabs
  • Origin
    Copied · affectUI · source
  • License
    MIT
  • Added
    Oct 18
npx shadcn@latest add @deank/segmented-control

The registry stays private. Install from the repo with a GitHub token — see the README.

Usage

import { SegmentedControl } from "@/registry/components/segmented-control/segmented-control";

<SegmentedControl options={[/* … */]} />

Props

NameTypeDefaultDescription
optionsSegmentOption[]{ value, label?, icon?, count?, badge?, disabled?, ariaLabel?, controls? } – two to six work best; give icon-only options an ariaLabel
valuestringControlled value
defaultValuestringfirst enabled optionStarting value when uncontrolled
onChange(value: string) => voidCalled with the new value – on click, while dragging the pill and on arrow keys
size"sm" | "md" | "lg""md"26, 30 or 36px tall options (40px+ on touch screens)
variant"tray" | "underline""tray"A gray track with a raised white pill, or text tabs on a hairline with a sliding line
fullWidthbooleanfalseFills its container with equal segments, each as wide as the widest one needs
kind"radio" | "tabs""radio"A radiogroup, or a tablist that switches panels (pair with controls on each option)
disabledbooleanfalseDisables the whole control
aria-labelstringNames the group – or use aria-labelledby
classNamestringExtra class on the root

When to use

- Switching between two to six views of the same content – sections of a dashboard, list / board / calendar, monthly / yearly - A choice that applies right away and where every option should stay visible

When not to use

More than six options, or multiple selection (filter-menu).

Related

Direction aware tabs · Tactile toggle