Segmented Control
A row of segments that switches between a few short options, like a view or an environment. A tinted thumb slides to the checked segment.
When to use
- Switch between a few short options in one compact, inline row, such as a view, an environment, or a filter.
- Prefer
RadioGroupfor a form field whose options need a description, or stack in a column. - Prefer
Tabswhen each option shows its own panel of content. - Prefer
Selectwhen the set is long, or the row has little space.
Controlled
Pass value and onValueChange to keep the checked segment in your own state. The control reports the new value on a click, a key, and a drag.
Icon segments
A segment can hold only an icon. Give each one its name in sr-only text, so a screen reader announces it. A segment whose children are an icon and sr-only text is square, like an IconButton. Set w-fit on the root, so the segments do not grow to fill the row.
Size
Set size on SegmentedControl.Root to set the height of the whole control, default md. The scale is the one Button, IconButton, and SplitButton use: xs, sm, md, lg, and xl. A control lines up with buttons of the same size in a toolbar. At xs, the labels are text-xs, so they have room inside the 16px thumb. Use a size-4 icon at xs and sm, and a size-5 icon from md up, as in an IconButton. A Button with appearance="link" has no box, so it has no height to match. The items do not accept size, so the items of one control always share one height.
With TanStack Form
Use @tanstack/react-form with zod to keep the control controlled in a form. Pass the field's name, value, and handleChange. Use Field.Set and Field.Legend to name the group and show its errors.
Composition
Radio semantics
SegmentedControl is a radio group of native radios. It shares its primitive with RadioGroup, so it has the same contract: role="radiogroup", one tab stop, arrow keys that move the checked segment, and form submission when it has a name. Each segment is a <div> with an invisible <input type="radio"> in it, so style a segment's state with has-[>input:checked]:, has-[>input:disabled]:, and has-[>input:focus-visible]:.
To change the value, click a segment, use the arrow keys, or drag the thumb with a mouse or a finger.
Dragging the thumb
A sideways drag on the checked segment moves the thumb with the pointer. On release, the thumb slides to the nearest enabled segment, and that segment becomes checked. A flick carries the thumb further. Past either end, the thumb meets resistance and stays inside the track. A drag that goes up or down more than sideways does not start, so the page still scrolls on a touch screen.
The thumb slides on every change: a click, a key, a drag, or a new value. With reduced motion, it moves at once.
API Reference
SegmentedControl.Root
The row of segments. It renders the radio group itself, so use it in place of RadioGroup.Root, never inside one.
The same props as RadioGroup.Root, including:
It also takes:
SegmentedControl.Item
One segment. It grows to share the row and keeps its label on one line, so keep labels to one or two words. Inside Field.Control, the segment picks up aria-invalid, aria-errormessage, and aria-describedby.