Xzero UI
Pro library

Segmented control

Switch between a small set of related views.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/segmented-control
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/segmented-control

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import SegmentedControl from "@/components/xzero/segmented-control/segmented-control";

export function RangeToggle() {
  const [range, setRange] = useState("week");
  return (
    <SegmentedControl
      label="Range"
      value={range}
      onValueChange={setRange}
      options={[
        { value: "day", label: "Day" },
        { value: "week", label: "Week" },
        { value: "month", label: "Month" },
      ]}
    />
  );
}

API reference

SegmentedControl

A row of toggle buttons with one selection pill that slides between them. Default export.

PropTypeDefaultDescription
options (required){ value: string; label: string; accessory?: ReactNode }[]–Segments in order. An accessory, such as a badge, renders after the label.
value (required)string–Selected value.
onValueChange (required)(value: string) => void–Called with the chosen segment's value, from a click or the arrow, Home and End keys.
labelstring–aria-label for the group.
onOptionIntent(value: string) => void–Called when the pointer or focus reaches a segment before it is chosen, to start loading what it shows.
classNamestring–Extra class on the root.

Keyboard interactions

KeysAction
TabMoves focus into the control, onto the selected segment, and out again.
Arrow keysSelect and focus the previous or next segment, wrapping at the ends.
Home / EndSelect the first or last segment.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in toggles

Guidance for AI tools

Segmented control: Switch between a small set of related views. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components