Loading component…
Loading component…
Switch between two to six options
To reuse this local React demo, copy all files from the Code tab into the same folder, then import SegmentedControl from ./segmented-control.
import { SegmentedControl } from "@/components/ui/segmented-control";
export function DashboardTabs() {
const [section, setSection] = useState("overview");
return (
<SegmentedControl
aria-label="Dashboard section"
kind="tabs"
value={section}
onChange={setSection}
options={[
{ value: "overview", label: "Overview", controls: "panel-overview" },
{ value: "analytics", label: "Analytics", controls: "panel-analytics" },
{ value: "reports", label: "Reports", controls: "panel-reports" },
{ value: "notifications", label: "Notifications", count: unread, controls: "panel-notifications" },
]}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| options | SegmentOption[] | { value, label?, icon?, count?, badge?, disabled?, ariaLabel?, controls? } – two to six work best; give icon-only options an ariaLabel | |
| value | string | Controlled value | |
| defaultValue | string | first enabled option | Starting value when uncontrolled |
| onChange | (value: string) => void | Called with the new value – on click, while dragging the pill and on arrow keys | |
| size | "sm" \| "md" \| "lg" | "md" | 26, 30 or 36px tall options (40px+ on touch screens) |
| variant | "tray" \| "underline" | "tray" | A gray track with a raised white pill, or text tabs on a hairline with a sliding line |
| fullWidth | boolean | false | Fills its container with equal segments, each as wide as the widest one needs |
| kind | "radio" \| "tabs" | "radio" | A radiogroup, or a tablist that switches panels (pair with controls on each option) |
| disabled | boolean | false | Disables the whole control |
| aria-label | string | Names the group – or use aria-labelledby | |
| className | string | Extra class on the root |
If it doesn't fit, it scrolls sideways with soft edges on the sides that hide options and keeps the active one in view
Touch screens: options are at least 40px tall; a tap picks on lift, so swiping to scroll never picks by accident
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.