When to use
- Picking one of two to five short options that change a value: a date range, a view density, a billing period.
- Filters and settings where every option should stay visible, so people see what they are not choosing.
- Inside forms: it submits its value through
namelike a radio group.
When not to use
- Swapping regions of content: use Tabs, which wire up panels.
- More than five options, or long labels: use a Radio Group or a select.
- Options that can be on at the same time: use Toggle Group.
Installation
pnpm dlx shadcn add https://eased.dev/r/segmented.jsonnpx shadcn add https://eased.dev/r/segmented.jsonyarn dlx shadcn add https://eased.dev/r/segmented.jsonbunx --bun shadcn add https://eased.dev/r/segmented.jsonThe command adds Segmented, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/reactAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/segmented/segmented.tsxTSX "use client";import { Radio } from "@base-ui/react/radio";import { RadioGroup } from "@base-ui/react/radio-group";import type { ReactNode } from "react";import { Indicator, IndicatorGroup } from "../_primitives/indicator/indicator";export type SegmentedOption<V extends string> = { value: V; /** The visible label. For an icon-only segment pass `icon` and an `aria-label` instead. */ label?: ReactNode; /** A 16px icon before the label. */ icon?: ReactNode; /** Required when there is no text label. */ "aria-label"?: string; disabled?: boolean;};export type SegmentedProps<V extends string> = { options: readonly SegmentedOption<V>[]; /** The selected value (controlled). */ value?: V; /** The initially selected value (uncontrolled). Defaults to the first option. */ defaultValue?: V; onValueChange?: (value: V) => void; /** `sm` is 32px (dense UI, toolbars, demo headers); `md` is 36px (forms, settings). Default `sm`. */ size?: "sm" | "md"; /** Stretch to the container and share the width equally between segments. */ fullWidth?: boolean; /** Submits the value with a form under this name. */ name?: string; disabled?: boolean; /** Accessible name, e.g. "Date range". Or point `aria-labelledby` at a visible label. */ "aria-label"?: string; "aria-labelledby"?: string; className?: string;};const SIZES = { sm: { track: "h-control-sm rounded-control-sm [--radius-outer:var(--eased-radius-control-sm)]", item: "gap-1.5 px-3 text-ui-sm", icon: "px-2", }, md: { track: "h-control-md rounded-control [--radius-outer:var(--eased-radius-control)]", item: "gap-2 px-3.5 text-ui", icon: "px-2.5", },} as const;/** * A single-choice control whose thumb glides to the selected segment on the snappy spring. * Base UI's RadioGroup supplies the behaviour: one tab stop, arrow keys move selection, * Home/End, form submission. Concentric by construction: the thumb's radius is the track's * minus its padding and border (`radius-nested`). Labels never change weight; the selected * one only darkens, and its cursor goes back to default because clicking it does nothing. * Segments carry no extended hit area: they sit edge to edge, and the track is the target. */export function Segmented<V extends string>({ options, value, defaultValue, onValueChange, size = "sm", fullWidth = false, name, disabled, className = "", ...aria}: SegmentedProps<V>) { const s = SIZES[size]; return ( <RadioGroup<V> value={value} defaultValue={value === undefined ? (defaultValue ?? options[0]?.value) : undefined} onValueChange={(next) => onValueChange?.(next)} name={name} disabled={disabled} {...aria} className={`${fullWidth ? "flex w-full" : "inline-flex"} shrink-0 items-stretch border border-line-subtle bg-surface-sunken p-0.5 [--border-w:1px] [--pad:2px] ${s.track} ${className}`} > <IndicatorGroup> {options.map((option) => ( <Radio.Root key={option.value} value={option.value} disabled={option.disabled} aria-label={option["aria-label"]} nativeButton render={(props, state) => ( <button type="button" {...props}> {state.checked && ( <Indicator className="inset-0 radius-nested bg-surface-raised shadow-thumb" /> )} {option.icon && <span className="relative z-1 flex size-4 shrink-0 items-center justify-center [&_svg]:size-4">{option.icon}</span>} {option.label !== undefined && <span className="relative z-1 truncate">{option.label}</span>} </button> )} className={(state) => `relative flex min-w-0 items-center justify-center font-medium whitespace-nowrap radius-nested select-none transition-[color,background-color,border-color,box-shadow] duration-150 ease-standard focus-ring ${ option.label === undefined ? s.icon : s.item } ${fullWidth ? "flex-1" : ""} ${ state.disabled ? "cursor-not-allowed text-text-disabled" : state.checked ? "cursor-default text-text" : "cursor-pointer text-text-muted hover-fine:text-text-secondary" }` } /> ))} </IndicatorGroup> </RadioGroup> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { useState } from "react";import { Segmented } from "@/components/eased/segmented/segmented";export function DateRange() { const [range, setRange] = useState("30d"); return ( <Segmented aria-label="Date range" options={[ { value: "7d", label: "7 days" }, { value: "30d", label: "30 days" }, { value: "12m", label: "12 mo" }, ]} value={range} onValueChange={setRange} /> );}Examples
Icon-only segments
Each icon-only segment needs its own aria-label.
<Segmented aria-label="Layout" options={[ { value: "list", icon: <ListIcon />, "aria-label": "List" }, { value: "grid", icon: <GridIcon />, "aria-label": "Grid" }, ]} defaultValue="list"/>Full width in a form
fullWidth splits the container equally; size="md" matches 36px form fields.
<Segmented name="billing" size="md" fullWidth aria-label="Billing period" options={periods} defaultValue="yearly" />API reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | { value, label?, icon?, "aria-label"?, disabled? }[] | Icon-only segments need an aria-label. | |
value / defaultValue | V | first option | Controlled or uncontrolled. |
onValueChange | (value: V) => void | ||
size | "sm" | "md" | "sm" | 32px for dense UI and headers, 36px for forms and settings. |
fullWidth | boolean | false | Fill the container and split it equally. |
name | string | Submits the value with a form. | |
disabled | boolean | ||
aria-label / aria-labelledby | string | Name the group. |
Keyboard
| Key | Action |
|---|---|
Tab | Moves focus to the selected segment; the whole control is one tab stop. |
← / → | Selects the previous or next segment. |
Home / End | Selects the first or last segment. |
Accessibility
- Base UI renders a
radiogroupofradios, so screen readers announce the group's name, the option and its position. - Name the group with
aria-label, oraria-labelledbypointing at a visible label. - Labels only darken when selected; they never change weight, so the segments keep their width.
Motion
The thumb glides to the new segment on the snappy spring and stays concentric with the track: its radius is the track's minus the padding and border. Reduced motion jumps the thumb to the new segment with no glide.
Notes for AI
Use Segmented for a short, visible single choice that sets a value, controlled with value and onValueChange or submitted with name. Keep labels to one or two words; switch to size="md" beside form fields.
Do not use it to switch views (that is Tabs), and do not add your own thumb, indicator or selected-weight styles: the component draws the thumb and keeps it concentric.
Related components
- Animated Tabs: switches a region of content.
- Animated Toggle Group: several options on at once.
- Radio Group and Radio Cards: longer lists and labels.