Forms
SegmentedControl
Free2.7 KB gzippedSingle-choice segmented control. See SegmentedControlProps; segments via options or SegmentedControl.Item.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Arrow keys · Full report
Import
import { SegmentedControl } from "@vjdesigns/vjdesigns-ui";
Importing only SegmentedControl adds about 2.7 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
A single choice from a few options, shown side by side. It's a radio group, so arrow keys move the selection.
import { useState } from "react";
import { SegmentedControl } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [view, setView] = useState("week");
return (
<SegmentedControl
label="Calendar view"
value={view}
onValueChange={setView}
options={[
{ value: "day", label: "Day" },
{ value: "week", label: "Week" },
{ value: "month", label: "Month" },
]}
/>
);
}
With icons
Compose SegmentedControl.Items to add icons. tone="primary" colors the selected segment.
import {
CalendarIcon,
ClockIcon,
MenuIcon,
SegmentedControl,
Stack,
} from "@vjdesigns/vjdesigns-ui";
export function WithIcons() {
return (
<Stack gap={4} align="center">
<SegmentedControl label="Layout" defaultValue="list" tone="primary" size="sm">
<SegmentedControl.Item value="list" icon={<MenuIcon />}>
List
</SegmentedControl.Item>
<SegmentedControl.Item value="calendar" icon={<CalendarIcon />}>
Calendar
</SegmentedControl.Item>
<SegmentedControl.Item value="timeline" icon={<ClockIcon />}>
Timeline
</SegmentedControl.Item>
</SegmentedControl>
</Stack>
);
}
Accessibility
Each segment is a native radio, so the control is one Tab stop and the arrow keys change the choice. label names the group; an icon-only segment needs an aria-label of its own.
import {
CalendarIcon,
ClockIcon,
MenuIcon,
SegmentedControl,
} from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<SegmentedControl label="View" defaultValue="list">
<SegmentedControl.Item value="list" icon={<MenuIcon />} aria-label="List view" />
<SegmentedControl.Item value="calendar" icon={<CalendarIcon />} aria-label="Calendar view" />
<SegmentedControl.Item value="timeline" icon={<ClockIcon />} aria-label="Timeline view" />
</SegmentedControl>
);
}
Translated
In Arabic the segments run right to left, and the arrow keys follow the reading direction. The segment labels are your own text.
import { SegmentedControl, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function Translated() {
return (
<LocaleProvider locale="ar" messages={ar}>
<SegmentedControl
label="الفترة"
defaultValue="week"
options={[
{ value: "day", label: "يوم" },
{ value: "week", label: "أسبوع" },
{ value: "month", label: "شهر" },
]}
/>
</LocaleProvider>
);
}
API reference
SegmentedControl
| Prop | Type | Default |
|---|---|---|
optionsSegments as data. Use this or | SegmentedControlOption[] | — |
children
| ReactNode | — |
valueSelected value (controlled). Use with | string | — |
defaultValueInitially selected value (uncontrolled). Leave unset for no initial selection (no thumb). | string | — |
onValueChangeCalled with the newly selected segment's | (value: string) => void | — |
nameShared | string | — |
sizeHeight and text size. Falls back to a surrounding Field's size. | "sm""md""lg" | "md" |
toneThumb color: raised neutral surface, or solid primary with on-primary text. | "neutral""primary" | "neutral" |
radiusCorner rounding of the track; the thumb and segments follow it. | "none""xs""sm""md""lg""xl""2xl""pill" | "pill" |
fullWidthStretch to the container's width with equal-width segments. | boolean | — |
orientationLay segments out in a row or a column. Arrow keys work in both directions either way. | "horizontal""vertical" | "horizontal" |
disabledDisables every segment. Falls back to a surrounding Field's state. | boolean | — |
invalidInvalid styling and | boolean | — |
requiredA selection is required: native | boolean | — |
labelVisible group label, shown above the track when the control stands alone. Ignored inside a | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
SegmentedControl.Item
One segment (a native radio).
| Prop | Type | Default |
|---|---|---|
valueRequiredValue submitted with the form and reported by | string | — |
iconDecorative icon before the label (e.g. | ReactNode | — |
disabledDisables this segment (the control's | boolean | — |
classNameClass for the segment (label) element. The | string | — |
childrenVisible segment label. | NonNullable<ReactNode> | — |
aria-labelOverrides the accessible name (rarely needed). | string | — |
Also accepts standard HTML attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
SegmentedControl targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves into the control, on the selected option. |
| Arrow keys | Moves to and selects the next or previous option, wrapping. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Control | radiogroup | aria-labelledby |
Option (<input type="radio">) | radio | Checked state is native |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |