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.
Interactive Preview
Section titled “Interactive Preview”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" /><script lang="ts"> import SegmentedControl from "@/components/ui/segmented-control.svelte";</script>
<script lang="ts"> const viewModes = [ { label: "Current workspace", value: "now" }, { label: "Example workspace", value: "new" }, ];</script>
<SegmentedControl label="View mode" items={viewModes} defaultValue="now" />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" />Installation
Section titled “Installation”Run the Glaceon CLI in your project root to automatically install the headless logic and copy the styled wrapper into your components folder.
npx @glaceon/cli add segmented-control --framework react # or svelte, solidInstall the Zag.js dependencies:
bun add @zag-js/react @zag-js/radio-groupCopy your framework’s implementation into your project. (Note: Code blocks omitted for brevity in preview, please refer to the source repository for full component code).
Data Attributes
Section titled “Data Attributes”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. |
API Reference (Props)
Section titled “API Reference (Props)”| 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. |
Keyboard Interactions
Section titled “Keyboard Interactions”| 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. |
Accessibility
Section titled “Accessibility”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.