Components / forms
SegmentedControl
One choice from two to four, drawn as a control bar rather than a list.
Summary
One choice from two to four, drawn as a control bar rather than a list.
| APG pattern | Radio Group |
| Built on | native elements |
| Status | self-tested |
| Since | 0.3.0 |
<SegmentedControl name="source" label="How to add a recipe" defaultValue="link"
options={[
{ value: 'link', label: 'From a link', icon: <Icon path={link} /> },
{ value: 'text', label: 'Pasted text', icon: <Icon path={note} /> },
{ value: 'manual', label: 'By hand', icon: <Icon path={pencilSimple} /> },
]} />
Anatomy
A <div data-se="segmented" role="radiogroup"> holding one <label data-part="segment"> per choice. Each segment wraps a native <input type="radio" data-part="control">, an optional leading icon carrying data-part="icon", and a <span data-part="label">.
| Part | Element | Required |
|---|---|---|
control | <input> | yes |
label | <span> | yes |
segment | <label> | yes |
<div data-se="segmented" data-emphasis="solid" data-size="sm" role="radiogroup" aria-label="How to add a recipe">
<label data-part="segment" data-se-text="ui">
<input data-part="control" type="radio" name="source" value="link" checked>
<svg data-part="icon" aria-hidden="true">…</svg>
<span data-part="label">From a link</span>
</label>
<label data-part="segment" data-se-text="ui">
<input data-part="control" type="radio" name="source" value="text">
<span data-part="label">Pasted text</span>
</label>
</div>
The root is the track. The design proposed a separate track part; it would exist only to hang a style off, so the root carries the fill, the edge and the inset instead.
The radio is real and invisible. It fills its segment, so a click lands on it directly and the label's implicit association covers the rest. Every state the segment paints is read off the input with :has() — a consumer writing the markup sets checked or disabled on the input and nothing else.
emphasis and size sit on the root, not on each segment. The design put data-emphasis on the segments; one attribute a consumer writes once is the same reasoning Tabs uses for data-orientation.
Properties
| Property | Values | Default | What it does |
|---|---|---|---|
name | string | required | Shared by every radio — this is what gives the control one tab stop and arrow keys. |
label | string | required | The accessible name of the group, written as aria-label. To name it from visible text beside it, pass aria-labelledby as well; that wins. |
options | SegmentedOption[] | required | The segments, in display order. Two to four; one is always chosen. |
value | string | none | The chosen value. Passing this makes the control controlled. |
defaultValue | string | none | Which segment starts chosen. Falls back to the first enabled one, because a segmented control with nothing chosen has no honest resting state. |
onChange | (value: string) => void | none | Called with the newly chosen value. |
emphasis | solid · outline | solid | solid sinks the track and lifts the chosen segment onto the surface. outline gives every segment its own edge, joined the way ButtonGroup joins its buttons. |
size | sm · md · lg | sm | sm lines up with a small Button and sits inside a form row. md matches a field. |
disabled | boolean | none | Disables every segment. To disable one, set it on the option. |
Two emphases, not three. transparent would be a row of unbordered labels with one lifted, which is the solid look without its track — there is nothing left to tell the reader where the control ends.
States
| State | Expressed as | |
|---|---|---|
| Checked | :checked | |
| Disabled | :disabled | |
| Focused | :focus-visible | |
| Hover | :hover |
All four belong to the input and are painted on the segment that wraps it.
Behavior
One segment is always chosen. Choosing another un-chooses the first; there is no empty state, and no way to clear it.
defaultValue falls back to the first enabled option. A disabled option is skipped by the arrow keys and cannot be chosen by a click, which the platform handles.
onChange is called with the new value once, on the change. It is not called on mount, and not called when the reader presses the segment that is already chosen.
Keyboard is in Accessibility.
Accessibility
Everything here comes from the platform. The binding writes no key handler and no aria-checked: native radios sharing a name are one tab stop, the arrow keys move focus and choose in one step, and the checked state is announced without an attribute. What the binding adds is the container's role and its name.
Keyboard
| Key | Result |
|---|---|
Tab | Enters the control once, on the chosen segment, and leaves it once — the whole control is one stop |
Arrow keys | Move to the next or previous segment and choose it, wrapping at either end. Disabled segments are skipped |
Space | Chooses the focused segment, if it was reached without choosing it |
Roles, states and properties
| Attribute | Set by |
|---|---|
aria-label | set at render |
role | always radiogroup |
The radios carry their own role and checked state. aria-label is the group's name; a caller passing aria-labelledby as well names it from visible text, which wins.
Focus
Tab lands on the chosen segment, never the first. The ring is drawn on the segment rather than on the invisible input, and the segment rises a layer while it holds focus so the outline emphasis, whose segments overlap by one border, never paints over one side of it.
Screen reader
Not recorded as verified. Stage 4 of the readiness ladder — driving each component with VoiceOver and NVDA — is unstarted across the package, and no component should claim otherwise until docs/journal/ records the session that did it.
Contrast and target size
npm run check:contrast audits every color pair this component uses across all four skins, light and dark, and fails the build on a shortfall. Two waivers are on the record in docs/audit/DEFERRED.md.
It takes the touch floor under (pointer: coarse) — the visual size is unchanged on a desktop pointer.
Tested
test/browser/control-width.spec.mjstest/browser/intent-tint-and-track-edge.spec.mjstest/browser/segmented-control.spec.mjs
Known gaps
_No upstream requirement is recorded as not applicable._
Appearance
| Token | Used for |
|---|---|
--se-border | border-color |
--se-border-strong | border-color |
--se-border-sunk | border |
--se-border-width | border, border-radius, margin-inline-start, padding |
--se-control-h | block-size |
--se-control-h-lg | block-size |
--se-control-h-sm | block-size |
--se-duration-instant | transition |
--se-ease-standard | transition |
--se-focus-color | outline |
--se-focus-offset | outline-offset |
--se-focus-width | outline |
--se-layer-raised | z-index |
--se-radius-track | border-end-end-radius, border-end-start-radius, border-radius, border-start-end-radius, border-start-start-radius |
--se-shadow-raised | box-shadow |
--se-space-2 | gap, padding-inline |
--se-surface | background |
--se-surface-sunk | background |
--se-target-min | min-block-size |
--se-text | color |
--se-text-disabled | color |
--se-text-muted | color |
Solid. The track is --se-surface-sunk inside a --se-border-sunk hairline at --se-radius-track: the edge is the border and the corner the medium radius unless the skin says otherwise, and davor-anic points the edge at the fill, so there is none, and the corner at a pill. The chosen segment is --se-surface with --se-shadow-raised; the rest are transparent and take --se-text-muted. The inset is one border plus one border's worth of padding, so the segment's radius is the track's minus twice --se-border-width — nested corners subtract, and no token is needed for a value no skin would set on its own.
Outline. The track is gone. Every segment draws its own --se-border edge on --se-surface-sunk, overlapping its neighbor by one border so the row draws one line; the chosen one takes --se-border-strong on --se-surface and sits at --se-layer-raised, so its darker edge is never cut.
Width is the segments' own, wherever the control sits. The track sets inline-size: fit-content, so a Field, a stack, a Card body or a grid cell does not stretch it across the container; a container narrower than the segments still wins. A consumer who wants a full-width bar sets the width on the root. Height is --se-control-h-sm, so it lines up with a small Button in a row, --se-control-h at md, or --se-control-h-lg at lg. The touch floor lifts the track under (pointer: coarse) and the segments stretch to fill it.
Motion
Background, edge, color and shadow cross over --se-duration-instant, the same step a button's hover takes. Nothing slides: a segment that moved between positions could not survive the row being one segment longer on a phone. prefers-reduced-motion collapses the transition through the reset.
Content
A segment label names the choice, not the action: From a link, Pasted text, By hand — not Add link. Two words at most; the segments never wrap, so a long label pushes the control off its row.
The group's label names the question the segments answer: How to add a recipe, View mode. It is heard once, before the segments.
A leading icon names the choice and is always paired with text. A control of icons alone is a ButtonGroup of icon-only buttons with aria-pressed, which is a different thing.
Usage
Use it for one choice from two to four that sits inside a form row — a source, a view mode, a unit. It costs one line and no legend.
Reach for RadioGroup when the choices need help text, when there are more than four, or when the question deserves a legend of its own. A radio group is a field; this is a control.
Reach for Tabs when the choice switches which panel of the page shows. Tabs own their region; this owns nothing beyond its edge.
Not a ButtonGroup. That is a set of actions, each of which happens and is over. This holds a value.
One emphasis per row. Solid is the default and reads as a control on any surface. Outline exists for a row of outline buttons, where a sunk track would be the one filled thing on the line.
Notes
The screen this came from drew the track and the lifted segment by hand out of Button and inline styles, which is the drift the contract exists to stop. docs/proposals/2026-08-22-component-inventory-and-the-second-batch.md already listed it in the fourth wave.
Building the segments as <button role="radio" aria-checked> was rejected. It reproduces roving focus, the arrow keys and the checked state in script for a pattern the platform already carries, and a Vue or Astro consumer would get the looks with none of the behavior. The native radio gives both for free.
A track part was rejected. The root is the track; a part that exists only to hang a style off is the thing the spec template says to call out.
emphasis moved from the segments, where the design put it, to the root. A consumer writes one attribute; the stylesheet reads it down, the way Tabs reads data-orientation from its root alone.