Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Segmented Control

A single-choice switcher for two to five short options. This is a radio group, not a button group: the options share one name, arrow keys move between them, and the browser’s radio semantics give the correct screen-reader announcement for free.

import { SegmentedControl } from "@/components/ui/segmented-control";
const viewModes = [
{ label: "Current workspace", value: "now" },
{ label: "Example workspace", value: "new" },
];
<SegmentedControl label="View mode" items={viewModes} defaultValue="now" />

Run the Glaceon CLI in your project root to automatically install the headless logic and copy the styled wrapper into your components folder.

Terminal window
npx @glaceon/cli add segmented-control --framework react # or svelte, solid

The checked segment is state, not styling: the active fill is driven entirely by data-state, so there is no separate “selected” class to keep in sync.

Element Data Attribute Value Description
root data-disabled "" Present when the whole group is disabled.
root data-orientation "horizontal" | "vertical" Layout axis.
root data-invalid "" Present when the group is marked invalid.
item data-state "checked" | "unchecked" The selected option.
item data-focus-visible "" Keyboard focus, as opposed to mouse focus.
item data-hover "" Pointer is over the item.
item data-active "" Pointer is held down on the item.
item data-disabled "" Present when the item cannot be chosen.
Prop Type Default Description
items { label: string, value: string }[] required The options.
value string undefined Controlled value.
defaultValue string undefined Initially selected value.
name string undefined Shared radio name, so the value participates in form submission.
label string undefined Accessible name for the group. Rendered visually hidden; pass a visible label from the surrounding FormField if you need one.
disabled boolean false Disables the whole group.
class / className string undefined Extra classes, appended last.
Key Description
Tab Moves into the group and lands on the checked option.
ArrowLeft / ArrowRight Moves the selection.
ArrowUp / ArrowDown Moves the selection when vertical.
Space Selects the focused option.

The checked segment is announced as a radio, not as a pressed button, because the hidden input carries type="radio" and the visible text is wired to it through aria-labelledby. The visible control is aria-hidden, so the label is not read twice.

White text on the checked segment (--green, #0F844F) measures 4.74:1, clearing the 4.5:1 needed for 14px bold text. The brand token was darkened from the mockup’s #12925A, which measured 3.97:1 and failed.