Raft Design System

Components · Navigation

SegmentedControl

2 to 4 segments in a gray track that switch how the same content is shown, in place; the selected segment is a yellow sticker.

StableAlso called Segmented button
import { SegmentedControl } from "@botiverse/raft-ui";

A segmented control switches between 2 to 4 views of the same content, in place: a board or a list of the same tasks, a light or a dark appearance. The segments sit in a gray track, and the selected one is a yellow sticker.

segmented-control/compositions/view-mode

When to use

SituationUse
Another view of the same content: Board / List, Light / Dark / SystemSegmentedControl
Sections of one page, each with its own contentTabs
An answer submitted with a form, such as public or privateRadioGroup
More options than fit as segmentsSelect
Several options that can be on together, such as runtimes to showCheckbox, or checkbox items in a DropdownMenu
Filtering, grouping or sorting a list: a status, a runtime, a grouping, a sortFilter buttons that show their values (Select › Filters)
A setting that already lives in a menuRadio or checkbox items in that DropdownMenu

A segmented control is one choice among 2 to 4 short options that all fit on one line: another view of the content right under it (Board / List), or a setting that applies at once (12-hour / 24-hour, Forms). Don't make segments of anything else (Artea, 2026-11-09, #proj-raft-ui:c1fde219):

  • Never let several segments be on at once. A row of segments reads as "pick one"; several picked reads as a bug. Options that combine are checkboxes.
  • Never let segments wrap onto a second line. A choice that needs more room is a Select or menu radio items.
  • Don't stack segmented controls for a list's filters, grouping and sort, in a toolbar or a sheet: they are filter buttons that show their values (Select › Filters). Nor for the settings of a menu: there each one is a group of radio or checkbox items, the way menus already show a choice.

The full table is in Choosing a component. Where Board / List goes on a task list is in Tasks.

Anatomy

  • SegmentedControl: the track, in fill-muted.
  • SegmentedControlItem: one segment, with an optional icon before its label, in a track 6px taller (3px padding). A segment is the same button as a tab in a row of Tabs at radius-control with 12px padding: 32px on a phone and a touch screen, and with a mouse on a desktop the control height, 34px (a 40px track), the one desktop size of a field, a select, a Button, a tab, a menu row and a sidebar row (stdrc, 2026-11-04).
  • SegmentedControlLabel: the segment's text. It truncates.
  • SegmentedControlCount: a count after the label, in Space Mono.
segmented-control/compositions/filters

States

  • Selected: a yellow sticker with a bold label. It doesn't change on hover, like a selected tab; a press lays sticker-medium (Hover and press).
  • The other segments are foreground-muted, with the medium tier, fill-medium, on hover and press.
  • Disabled: set on the whole control, as in States.
  • In the frame (a top bar), set variant="on-frame": the track is the frame's medium fill, the other segments are foreground-on-frame-muted (foreground-on-frame and the frame's medium overlay, overlay-frame-medium, on hover and press), and the selected segment takes the frame's active colors, layer-frame-active with a line-frame-active edge and foreground-on-frame-active text: white on the yellow frame, yellow on the dark one, as a selected rail item. A yellow sticker on the yellow frame would not read as selected, and the white segment beside it would look chosen instead. On a phone, where the top bar has no room for it, put the control in the menu rather than the bar.
segmented-control/compositions/disabled

Behavior

  • The segments sit 3px inside the track and 3px apart, so the gap between two of them is the gap to the track (Spacing).
  • Put a segmented control on the page's background, with the content it switches right under it. Don't give a row that holds only the segmented control a bar of its own with a divider above or below it: the control belongs to its content (Desktop density). A toolbar of several tools keeps its seam.
  • When it is the only thing in its row, start it at the row's start. Put it at the end only beside other tools grouped there on purpose (stdrc, 2026-11-04).
  • A lone segmented control under a head is part of the content, and its space says so: above it, the content's top inset (page-top: 12px with a mouse, the page inset on a touch screen, as far as the content starts under a head with no control); below it, the gap inside a group (8px) to the first item of the content, so the larger gap is above and it reads as one unit with what it switches. Its track starts on the content's margin, not under the head's buttons (stdrc, 2026-11-05; Desktop density).
  • The track hugs its segments. Don't stretch it to fill its container: a stretched track leaves an empty run of gray beside the segments.
  • The segments never shrink. When the row is too narrow, its neighbors give way first, then the segments show only their icons (Responsive layout). If the row is narrower still, or the caller set no iconsOnlyBelow, the track shrinks to the row and its segments scroll sideways inside it, the checked one kept in view, rather than spilling onto the next control: it sets data-overflowing while they do. Treat that as the last resort it is, not as the layout: in a row that may narrow, set iconsOnlyBelow="auto".
  • To let the segments show only their icons, set iconsOnlyBelow="auto". The control then shows only its icons exactly when its labelled segments don't fit the width it is given, and its labels again once they fit. Every segment becomes a square as tall as the segment (32px) that shows only its icon: its label and its count stay its accessible name, and its label shows in a tooltip on hover and on keyboard focus. The control keeps its height and its text size. Set iconsOnlyBelow only when every segment has an icon: a segment without one would be left empty, and raft-ui warns in development.
  • Prefer auto to a width. The labels' width changes with the language, a count and the font, so a width picked for one of them is wrong for the others, and the width the control is given changes with what sits beside it (a Mark all read button that comes and goes). auto measures the labelled segments against the room the control is given, whatever sits beside it: in a row, leave the control free to shrink (it is min-w-0; don't make it shrink-0) and let it share the row with its neighbors. It decides before the first frame paints and again whenever the room, a label, a count or the selection changes, and always against the labelled layout, so it comes back to its labels only once they fit and never flickers at the boundary.
  • Inside a FitToolbar the control follows the toolbar: give it the toolbar's label step (spread useFitItem({ label })'s props on it) and it shows only its icons while that step is taken. Its own iconsOnlyBelow is off there, so the toolbar and the control never measure the same room twice and disagree; the toolbar knows what else gives way first. A control of text alone (Mine and All with their counts) refuses that step and keeps its labels, since with no icons there would be nothing left to show (Jasper and sindresorhus, 2026-11-10).
  • To switch at a fixed row width instead, set iconsOnlyBelow to the row width below which the segments show only their icons, and mark the row with @container. Give either one of Tailwind's container sizes, xs (20rem), sm (24rem), md (28rem), lg (32rem), xl (36rem) or 2xl (42rem), which becomes a CSS container query, or any length in px, rem or em ("18.5rem", "296px"), which is measured in script against the nearest @container (the control's parent when there is none). Pick the width from the row, not the window: the same row sits in columns of different widths, and both follow the column.
  • Stretch it only when it is the only choice in a form. Then give it the full width (w-full) on its own line, not in a row beside other controls, and let the segments share it equally: in a row, a full-width track that can't shrink pushes past its neighbors.
  • On a phone, use at most 4 segments and show only their icons when they don't fit, with iconsOnlyBelow="auto" (Responsive layout).
  • On a touch screen a segment switches when the finger lifts, so a tap that stops a scrolling list still switches (Switching on finger lift).
segmented-control/compositions/fit-row

With auto or a length, the track carries data-icons-only while its segments show only their icons, for a caller that styles a part by it (in-data-icons-only:). With a size it is a container query, and the track carries nothing.

segmented-control/compositions/narrow-row

Content

  • Label each segment with 1 or 2 words in sentence case: Board, List; Relevant, Recent (Typography).
  • Put a count in SegmentedControlCount, never in the label's text.
  • Give everything of one kind the same segments, whether or not each has something in it now. A segment that is empty stays, with its count at 0 and an empty state behind it: an agent whose runtime can start sub-agents always shows Sub-agents in its Activity, 0 included (stdrc, 2026-11-14). A control that grows a segment when the first item arrives changes shape under the hand, and the place to look isn't there until people no longer need to look for it. Leave a segment out only for an item that can never have anything in it (a runtime that can't start sub-agents has no Sub-agents). Where that can't be known in advance, add the segment the first time there is something, and keep it.
  • Put the default option first: Cards before List where cards are the default, System before Light and Dark (stdrc, 2026-11-05). The keyboard order follows. An order that is a scale or a place (Small, Medium, Large; Top, Middle, Bottom) keeps it.

Accessibility

  • SegmentedControl wraps the Base UI RadioGroup, and each SegmentedControlItem is a Base UI Radio rendered as a button: the control is one tab stop, and the arrow keys move the selection.
  • Inside a FitToolbar the control is one item of the toolbar, so the toolbar stays one tab stop: its segments are in the tab order only while the control holds the toolbar's stop, and the toolbar's arrow keys move focus through the segments, in reading order with the toolbar's other controls, without choosing one; Space chooses (a Base UI radio ignores Enter on purpose), and Up and Down choose nothing. A second tab stop inside a toolbar, and arrow keys that chose as they moved, would break the toolbar's one-stop keyboard model (FitToolbar › Accessibility, WCAG 2.4.3).
  • A control rendered before it is in the document (into a host attached after its first commit, or a portal that mounts later) keeps a segment in the tab order once it is attached, the checked one or else the first, with nothing remounted. Base UI's radio group numbers only the segments connected when they register, so before, every segment kept tabIndex -1 and Tab passed over the control (slock's channel Tasks section, #14149): the control watches the document while it is detached, and once attached its segments register again.
  • Name the control with aria-label after what it switches: "Task view", "Time format".
  • Give every icon-only segment an aria-label. A segment that shows only its icon because of iconsOnlyBelow needs none: its label is still in it, hidden from sight but not from assistive technology.

API

SegmentedControl

PropTypeDefault
iconsOnlyBelowWhen every segment shows only its icon (give each one); its label stays the accessible name and shows in a tooltip. `auto`: when the labelled segments don't fit the width the control is given. A preset (`xs` to `2xl`) or a CSS length (`"18.5rem"`, `"296px"`): when the nearest `@container` ancestor (the row the control sits in) is narrower than it.SegmentedControlIconsOnlyBelow
variant`on-frame` in the frame (a top bar): the track the frame's medium fill and the selected segment in the frame's active colours (white on the yellow frame, yellow on the dark one), since a yellow sticker on yellow would not read as selected."default" | "on-frame""default"
defaultValueThe uncontrolled value of the radio button that should be initially selected.T
disabledWhether the component should ignore user interaction.booleanfalse
formIdentifies the form that owns the radio inputs. Useful when the radio group is rendered outside the form.string
inputRefA ref to access the hidden input element.((instance: HTMLInputElement | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<HTMLInputElement | null>
nameIdentifies the field when a form is submitted.string
onValueChangeCallback fired when the value changes.(value: T, eventDetails: BaseRadioGroup.ChangeEventDetails) => void
readOnlyWhether the user should be unable to select a different radio button in the group.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
requiredWhether the user must choose a value before submitting a form.booleanfalse
valueThe controlled value of the radio item that should be currently selected.T

Also takes the attributes of its element.

SegmentedControlCount

Takes the attributes of its element.

SegmentedControlItem

PropTypeDefault
disabledWhether the component should ignore user interaction.boolean
inputRefA ref to access the hidden input element.((instance: HTMLInputElement | null) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; }) | DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | RefObject<HTMLInputElement | null>
nativeButtonWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.booleanfalse
readOnlyWhether the user should be unable to select the radio button.boolean
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
requiredWhether the user must choose a value before submitting a form.boolean
value (required)The unique identifying value of the radio in a group.T

Also takes the attributes of its element.

SegmentedControlLabel

Takes the attributes of its element.

Changes

  • 0.9.0 · AddedSegmentedControl takes iconsOnlyBelow ("xs" to "2xl", Tailwind's container sizes; type SegmentedControlIconsOnlyBelow). Mark the row @container; below that width each segment shows only its icon as a 32px square, its label and count stay the accessible name, and a tooltip shows the label. Use it only when every segment has an icon.
  • 0.8.0 · Breaking ChangesSegmentedControl no longer shrinks with max-w-full; it keeps its width (shrink-0). In a narrow row, give it room or let the row degrade as responsive.md says, or it overflows.
  • 0.8.0 · FixedSegmentedControl keeps its width and no longer gets squeezed by a neighbor in the same row.