Segmented control
A compact single-choice control for switching between a few views or modes.
Use a segmented control to switch between two to five short options that change a view in place, such as Monthly and Yearly prices or List and Board. For a choice inside a form with longer labels, use a radio group; for switching between panels of content, use tabs.
Installation
Pro components install from the Aloxe registry with the shadcn CLI. Once per project, add the registry to components.json and put a registry token in the ALOXE_TOKEN environment variable. Registry has the details.
{
"registries": {
"@aloxe": {
"url": "https://<aloxe-site>/r/{name}.json",
"headers": { "Authorization": "Bearer ${ALOXE_TOKEN}" }
}
}
}Then add the component:
npx shadcn@latest add @aloxe/segmented-controlThe CLI copies the source into components/ui/aloxe/, so it never overwrites your own ui components. It also installs @aloxe/react, @aloxe/tokens and @base-ui/react.
Import the tokens once in your global stylesheet, after Tailwind, and add an @source for the copied files and one for @aloxe/react, so Tailwind generates their classes. @source paths are relative to the stylesheet; these assume src/app/globals.css and src/components/ui/aloxe/.
@import "tailwindcss";
@import "@aloxe/tokens/aloxe.css";
@import "@aloxe/tokens/tailwind.css";
@source "../components/ui/aloxe";
@source "../../node_modules/@aloxe/react/dist";Installation covers the theme and brand attributes.
Usage
import { SegmentedControl, Segment } from "@/components/ui/aloxe/segmented-control";
<SegmentedControl aria-label="Billing period" defaultValue="yearly" name="billing">
<Segment value="monthly">Monthly</Segment>
<Segment value="yearly">Yearly</Segment>
</SegmentedControl>The control needs a name: aria-label, or aria-labelledby pointing at a visible label. TypeScript requires one of the two. Keep each label to one or two words.
Examples
Controlled, with icons and a visible label
Pass value and onValueChange; the value type follows your segments. Icons go before the label at 16 px.
24 tasks in 4 columns: To do, In progress, Review, Done.
Disabled
A disabled segment is dimmed and skipped by the arrow keys. disabled on the control dims every segment.
Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus into the control, onto the selected segment, and out again. |
| Right and Down | Selects the next segment, wrapping at the end. |
| Left and Up | Selects the previous segment, wrapping at the start. |
- Follows the WAI-ARIA radio group pattern: the control is a
radiogroupand each segment is aradio, so screen readers announce "2 of 3, selected". - The selected segment differs by its raised surface, its shadow in light mode and a hairline ring in dark mode, not by colour alone.
- Segments are 28 px tall in a 32 px track. For touch-first layouts, stretch the control with
className="w-full"so each segment is wide enough to tap.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="segment"].
SegmentedControl
Extends Base UI RadioGroup.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | Names the radio group. Required unless you pass aria-labelledby. | |
| aria-labelledby | string | The id of a visible label. Required unless you pass aria-label. | |
| value | Value | Controlled value. Pair with onValueChange. | |
| defaultValue | Value | Initial value when uncontrolled. | |
| onValueChange | (value: Value, details) => void | Called when the user picks a segment. The value type follows your segments. | |
| name | string | Form field name. The selected value is submitted with the form. | |
| disabled | boolean | false | Disables every segment. |
| className | string | Classes for the track, such as w-full to stretch the segments. |
Segment
Extends Base UI Radio.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | Value | The value this segment selects. | |
| children (required) | ReactNode | The label, one or two words. An icon may go before it. | |
| disabled | boolean | false | Dims the segment. The arrow keys skip it. |
| className | string | Merged with the default classes. |
Figma
Matches the Segmented control and Segment components in the Pro Figma file. Segment State=Selected is the control's value; Disabled maps to disabled.
See Figma for where to get the file and how its names map to code.
Pro
Segmented control is part of Aloxe Pro. The previews on this page are open to everyone; the Code tab shows the example source once you sign in with a Pro license. See Access and licenses and Pricing.