Segment
- Stable
- WCAG 2.2 evidence
- RTL
One option of a {@link SegmentedControl }. Inside the control it is a radio (aria-checked) and
the control owns the selection; arrow keys move focus between segments and Enter or Space selects (WCAG 2.1.1, 4.1.2).
Built on React Aria ToggleButton; Figma advises against using it on its own, where it would be a toggle button
with isSelected / defaultSelected / onChange. The selected segment differs by elevation (raised fill, Shadow/sm) and weight (Body/Strong), not by colour alone
(WCAG 1.4.1). Consumer duties: short, translated labels and a Tooltip for icon-only segments.
import { Segment } from "@nexera-ui/react";- 3
- examples
- 18
- props
- 2
- live controls
- 1
- platform
- 10
- 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 { Segment } from "@nexera-ui/react";
<Segment />Examples 2
The same examples as Storybook, rendered live. Open Code to copy one.
With icon
Figma Show icon: a 16 px icon 6 px before the label, or an icon-only segment named by aria-label.
import { Segment, SegmentedControl } from "@nexera-ui/react";
import { LuCalendarDays, LuList } from "react-icons/lu";
export function WithIcon() {
return (
<SegmentedControl aria-label="Layout" defaultSelectedKeys={["list"]}>
<Segment id="list" label="List" icon={<LuList />} />
<Segment id="calendar" label="Calendar" icon={<LuCalendarDays />} />
<Segment id="calendar-only" aria-label="Calendar (compact)" icon={<LuCalendarDays />} />
</SegmentedControl>
);
}
Disabled
Figma Disabled state, on one segment and on a whole control (the selected chip stays visible).
import { Segment, SegmentedControl } from "@nexera-ui/react";
export function Disabled() {
return (
<div className="flex flex-col items-start gap-4">
<SegmentedControl aria-label="View" defaultSelectedKeys={["day"]}>
<Segment id="day" label="Day" />
<Segment id="week" label="Week" isDisabled />
<Segment id="month" label="Month" />
</SegmentedControl>
<SegmentedControl aria-label="View (read only)" isDisabled defaultSelectedKeys={["week"]}>
<Segment id="day" label="Day" />
<Segment id="week" label="Week" />
</SegmentedControl>
</div>
);
}
Props 18
Press "Try it" on a card to load that prop into the playground.
18 props shown
id*NexeraKeyKey of the segment in the SegmentedControl selection (selectedKeys, onSelectionChange). Required: without it
the control cannot track the segment. On a standalone segment it is used as the DOM id.
iconNexeraReactNodeIcon before the label. 16 px, decorative, shown
when provided. An icon-only segment needs aria-label or aria-labelledby.
classNameNexerastringExtra classes, merged last so they win over the defaults.
styleNexeraCSSPropertiesInline style.
labelNexeraVisibleContentVisible label, for example "Week" or "3M". It is the accessible name; it wraps. No visible label.
aria-labelNexerastringOverrides the name given by label. Avoid: the name must contain the visible text (WCAG 2.5.3).
Accessible name of an icon-only segment. Translate it, and show the same text in a Tooltip.
Accessible name; aria-labelledby wins when both are set.
aria-labelledbyNexerastringId(s) of element(s) that name the segment instead of label.
Id(s) of element(s) that name the segment; wins over aria-label.
Id(s) of visible element(s) that name the segment.
aria-describedbyReact AriastringIdentifies the element (or elements) that describes the object.
isSelectedReact AriabooleanWhether the element should be selected (controlled).
defaultSelectedReact AriabooleanWhether the element should be selected (uncontrolled).
onChangeReact Aria(isSelected: boolean) => voidHandler that is called when the element's selection state changes.
isDisabledReact AriabooleanWhether the button is disabled.
onPressReact Aria(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStartReact Aria(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEndReact Aria(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChangeReact Aria(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUpReact Aria(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
autoFocusReact AriabooleanWhether the element should receive focus on render.
* 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
5 direct · 5 supporting- 1.1.1Non-text ContentLevel A · tested directly
- 1.3.1Info and RelationshipsLevel A · tested directly
- 1.4.1Use of ColorLevel A · supporting test
- 1.4.4Resize TextLevel AA · supporting test
- 1.4.11Non-text ContrastLevel AA · supporting test
- 1.4.12Text SpacingLevel AA · supporting test
- 2.1.1KeyboardLevel A · tested directly
- 2.4.7Focus VisibleLevel AA · tested directly
- 2.5.8Target Size (Minimum)Level AA · supporting test
- 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:.
data-disableddata-focus-visibledata-hovereddata-selected
<Segment className="data-disabled:opacity-90 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.