Skip to content

Segmented Control for React

An iOS-style segmented control for React where a glass pill slides to the chosen segment and the arrow keys move between segments.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/segmented.json

Showing the list view

With icons

When its container gets narrow, the control tightens its padding, then shows icons only (each label stays the segment's accessible name and becomes its tooltip). Labels only truncate as a last resort. Resize the window to see it.

Showing the board view

Files to copy

5 folders · 6 files · 4 packages
From theme/src/
  • components/segmented/
  • hooks/{use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, form.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/segmented.jsonRegistry item: segmented. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Sizes

sm, md and lg. On touch screens every size is at least 44px tall.

Full width and icon only

fullWidth shares the row equally, which suits phones and narrow cards. iconOnly hides the labels; each one becomes the segment's accessible name and tooltip.

Theme

Props

PropTypeDefaultDescription
aria-describedbystringNoneIds of elements that describe the field, merged with the control's own description and error ids.
aria-invalidboolean | "true" | "false"NoneMarks the field as invalid (also set automatically when error is shown).
onBlurFocusEventHandler<HTMLElement>NoneCalled when focus leaves the control (not when it moves between the control's own parts).
namestringNoneSubmits the chosen value with a form (a hidden input).
disabledbooleanfalseDisables every segment of the control.
items (required)SegmentedControlItem[]NoneThe segments to show, in order.
valuestringNoneSets the chosen value when controlled.
defaultValuestringthe first enabled itemSets the starting value when uncontrolled.
onValueChange((value: string) => void)NoneCalled with the new value when a different segment is chosen.
size"sm" | "md" | "lg""md"Height and text size: "sm" (28px), "md" (32px, default) or "lg" (40px).
fullWidthbooleanfalseStretch to the container's width; segments share it equally.
iconOnlybooleanfalseShow only the icons. Each item's label (or aria-label) becomes its accessible name and tooltip.
adaptivebooleantrueWhen the container is too narrow: tighten the padding, then (if every segment has an icon) show icons only, then truncate labels. Off: labels truncate straight away.
aria-labelstringNoneName of the control for screen readers, when no visible label points at it.
aria-labelledbystringNoneId of an element that names the control.
classNamestringNoneAdds extra classes to the glass track.

Keyboard

KeysAction
Tab/Shift + TabEnter or leave the control once, on the chosen segment.
Arrow Left/Arrow Right (or Up/Down)Move between segments.
Home/EndJump to the first or last segment.
Enter/SpacePick the focused segment.

Accessibility

  • A group of toggle buttons with aria-pressed: name the group with aria-label or aria-labelledby.
  • iconOnly segments keep their label as the accessible name. Segments are 44 px tall on touch screens.
  • In forced colors the chosen segment is outlined and underlined, since the pill's fill is dropped.

When to use the segmented control

  • Use it as a toggle button group for a chart toolbar that switches between Day, Week and Month, where the choice changes how the same data is shown and a sliding glass pill marks the current one. It gives you an iOS segmented control look in CSS without custom styling, with one glass pill that slides to the chosen segment.
  • Use it for a List or Grid view toggle above a gallery, with icons on each item and iconOnly for narrow headers where labels become accessible names and tooltips.
  • Use it inside a narrow sidebar or a mobile header, since the adaptive default tightens padding first, then switches to icons only if every segment has one, and only then truncates labels.
  • Skip it when each choice swaps a whole panel of content; Tabs gives the right semantics there, and RadioGroup fits a form answer with longer labels and descriptions.
  • Pair it with a visible label that points at it through aria-labelledby (or aria-label), Button or Badge elsewhere in the same toolbar, and the chart or DataTable you are filtering by the chosen value.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .