Segmented Control
- Needs review
- WCAG 2.2 evidence
- RTL
A single choice between two to four closely related options, such as a chart range (3M / 6M / 12M) or a calendar
view (Day / Week / Month).
Built on React Aria ToggleButtonGroup with single selection: a named radiogroup of Segment radios. Arrow keys
move focus between segments (mirrored in right-to-left locales), Enter and Space select, Tab leaves the control
(WCAG 2.1.1, 4.1.2). Controlled with selectedKeys and onSelectionChange, uncontrolled with defaultSelectedKeys. Consumer duties: a name for the control, short translated labels, and a default selection.
import { SegmentedControl } from "@nexera-ui/react";- 5
- examples
- 11
- props
- 3
- live controls
- 1
- platform
- 5
- WCAG criteria
- 10
- blocks use it
Try every prop. Copy the code.
Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.
import { SegmentedControl } from "@nexera-ui/react";
<SegmentedControl />Examples 4
The same examples as Storybook, rendered live. Open Code to copy one.
Options
Figma Options = 2, 3 and 4, derived from the number of Segment children.
import { Segment, SegmentedControl } from "@nexera-ui/react";
export function Options() {
return (
<div className="flex flex-col items-start gap-4">
<SegmentedControl aria-label="Two options" defaultSelectedKeys={["month"]}>
<Segment id="week" label="Week" />
<Segment id="month" label="Month" />
</SegmentedControl>
<SegmentedControl aria-label="Three options" defaultSelectedKeys={["month"]}>
<Segment id="week" label="Week" />
<Segment id="month" label="Month" />
<Segment id="quarter" label="Quarter" />
</SegmentedControl>
<SegmentedControl aria-label="Four options" defaultSelectedKeys={["month"]}>
<Segment id="day" label="Day" />
<Segment id="week" label="Week" />
<Segment id="month" label="Month" />
<Segment id="year" label="Year" />
</SegmentedControl>
</div>
);
}
Chart range
The chart range control is this component with three segments, named by the chart title through aria-labelledby.
import { Segment, SegmentedControl } from "@nexera-ui/react";
export function ChartRange() {
return (
<div className="flex flex-wrap items-center gap-4">
<h3 id="chart-range-title" className="m-0 text-heading-h4 text-primary">
Headcount
</h3>
<SegmentedControl aria-labelledby="chart-range-title" defaultSelectedKeys={["6m"]}>
<Segment id="3m" label="3M" />
<Segment id="6m" label="6M" />
<Segment id="12m" label="12M" />
</SegmentedControl>
</div>
);
}
With icons
Segments with icons, and icon-only segments named by aria-label.
import { Segment, SegmentedControl } from "@nexera-ui/react";
import { LuCalendarDays, LuChartColumn, LuList } from "react-icons/lu";
export function WithIcons() {
return (
<div className="flex flex-col items-start gap-4">
<SegmentedControl aria-label="Layout" defaultSelectedKeys={["list"]}>
<Segment id="list" label="List" icon={<LuList />} />
<Segment id="calendar" label="Calendar" icon={<LuCalendarDays />} />
<Segment id="chart" label="Chart" icon={<LuChartColumn />} />
</SegmentedControl>
<SegmentedControl aria-label="Layout (compact)" defaultSelectedKeys={["list"]}>
<Segment id="list" aria-label="List" icon={<LuList />} />
<Segment id="calendar" aria-label="Calendar" icon={<LuCalendarDays />} />
<Segment id="chart" aria-label="Chart" icon={<LuChartColumn />} />
</SegmentedControl>
</div>
);
}
Long labels
Labels wrap instead of truncating; the other segments stretch to the same height.
import { Segment, SegmentedControl } from "@nexera-ui/react";
export function LongLabels() {
return (
<div className="max-w-xs">
<SegmentedControl aria-label="Period" defaultSelectedKeys={["month"]}>
<Segment id="month" label="This month" />
<Segment id="ytd" label="Year to date, including the current month" />
<Segment id="all" label="All" />
</SegmentedControl>
</div>
);
}
Props 11
Press "Try it" on a card to load that prop into the playground.
11 props shown
children*NexeraReactNodeThe options: two to four Segment elements. Use a Select for
more options and Tabs for sections of a page.
disallowEmptySelectionNexerabooleanKeeps one segment selected: pressing the selected segment again does nothing. Set to false to let users clear
the selection.
classNameNexerastringExtra classes, merged last so they win over the defaults.
styleNexeraCSSPropertiesInline style.
aria-labelNexerastringAccessible name of the choice ("Range", "Period"). Translate it.
Accessible name; aria-labelledby wins when both are set.
aria-labelledbyNexerastringId(s) of element(s) that name the control; wins over aria-label.
Id(s) of the visible element(s) that name the control, for example the chart title.
selectedKeysReact AriaIterable<Key>The currently selected keys in the collection (controlled).
defaultSelectedKeysReact AriaIterable<Key>The initial selected keys in the collection (uncontrolled).
onSelectionChangeReact Aria(keys: Set<Key>) => voidHandler that is called when the selection changes.
isDisabledReact AriabooleanWhether all items are disabled.
aria-describedbyReact AriastringIdentifies the element (or elements) that describes the object.
* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.
Accessible by default.
Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.
WCAG 2.2 evidence
3 direct · 2 supporting- 1.3.1Info and RelationshipsLevel A · tested directly
- 1.4.10ReflowLevel AA · supporting test
- 1.4.12Text SpacingLevel AA · supporting test
- 2.1.1KeyboardLevel A · tested directly
- 4.1.2Name, Role, ValueLevel A · tested directly
Fits any width.
Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.
Styling hooks
Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.
<SegmentedControl className="shadow-sm" />Used in blocks
- Choose a planOnboarding
- Sales dashboardDashboards and analytics
- Chart statesDashboards and analytics
- AppearanceSettings and preferences
- Team availabilityScheduling and calendar
- Pricing plansCommerce and payments
- Reviews and ratingsCommerce and payments
- People nearbyMaps and places
- Error pagesStates and system messages
- Colour sheetMobile patterns
Related components
- BoardCardA Kanban card: avatar, name, role, drag handle and a detail line.
- ButtonTriggers an action such as Save, Submit, Approve or Delete.
- ButtonGroupItemOne toggle in a joined row of buttons, for example a List / Grid view switch or a set of filters.
- ContextMenuThe menu of actions for an element, opened where the user asks for it: right-click, long-press on touch screens, and from the keyboard with Shift+F10 or the ContextMenu key (the browser reports both as a `contextmenu` event on the focused element; on macOS, Control+Enter).
- DragHandleGrip that starts a drag of the collection item it sits in.
- DropIndicatorInsertion line shown between two items while something is dragged over a `GridList` or `ListBox`.
- IconButtonA square, icon-only button for compact actions such as Settings, Close or Delete row.
- MenuA list of actions or options that opens from a trigger.