Segmented Control
SegmentedControl lets users pick one option from a compact horizontal group.
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
<SegmentedControl aria-label="View" defaultValue="board">
<SegmentedControl.Item value="list">List</SegmentedControl.Item>
<SegmentedControl.Item value="board">Board</SegmentedControl.Item>
<SegmentedControl.Item value="calendar">Calendar</SegmentedControl.Item>
</SegmentedControl>Installation
pnpm dlx wideset add segmented-control
Copies the component and any Wideset components it uses into your project.
Examples
Variants
Regular sizes each segment to its label and suits toolbars and headers. Full width shares the container's width evenly, for two to four segments in a panel or a card. The control is a single tab stop either way; the arrow keys move between segments and select the focused segment.
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
export default function SegmentedControlVariants() {
return (
<div className="gap-ws-12 flex w-[24rem] max-w-full flex-col items-start">
{(['regular', 'fullWidth'] as const).map((variant) => (
<SegmentedControl key={variant} aria-label="Period" variant={variant} defaultValue="week">
<SegmentedControl.Item value="day">Day</SegmentedControl.Item>
<SegmentedControl.Item value="week">Week</SegmentedControl.Item>
<SegmentedControl.Item value="month">Month</SegmentedControl.Item>
</SegmentedControl>
))}
</div>
);
}Sizes
Medium is the default. Small fits dense toolbars and table headers; large gives the control more presence next to large buttons and inputs. Match the size of the controls beside it.
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
export default function SegmentedControlSizes() {
return (
<div className="gap-ws-12 flex flex-col items-start">
{(['sm', 'md', 'lg'] as const).map((size) => (
<SegmentedControl key={size} aria-label="Period" size={size} defaultValue="week">
<SegmentedControl.Item value="day">Day</SegmentedControl.Item>
<SegmentedControl.Item value="week">Week</SegmentedControl.Item>
<SegmentedControl.Item value="month">Month</SegmentedControl.Item>
</SegmentedControl>
))}
</div>
);
}Icons
An icon next to a label helps recognition; icon-only segments, set with icon or with a lone SegmentedControl.Icon child, become square and need an aria-label each (the item warns in the console without one). Do not mix the two in one control.
import { RiCalendarLine, RiLayoutColumnLine, RiListCheck2 } from '@remixicon/react';
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
export default function SegmentedControlIcons() {
return (
<div className="gap-ws-9 flex flex-wrap items-center justify-center">
<SegmentedControl aria-label="View" defaultValue="board">
<SegmentedControl.Item value="list">
<SegmentedControl.Icon icon={RiListCheck2} />
List
</SegmentedControl.Item>
<SegmentedControl.Item value="board">
<SegmentedControl.Icon icon={RiLayoutColumnLine} />
Board
</SegmentedControl.Item>
<SegmentedControl.Item value="calendar">
<SegmentedControl.Icon icon={RiCalendarLine} />
Calendar
</SegmentedControl.Item>
</SegmentedControl>
<SegmentedControl aria-label="View" defaultValue="board">
<SegmentedControl.Item value="list" icon={RiListCheck2} aria-label="List view" />
<SegmentedControl.Item value="board" icon={RiLayoutColumnLine} aria-label="Board view" />
<SegmentedControl.Item value="calendar" icon={RiCalendarLine} aria-label="Calendar view" />
</SegmentedControl>
</div>
);
}States
Hover, press and keyboard focus are live. disabled on one item takes only that segment out of reach; disabled on the control disables all of them and keeps the current selection visible. Say why a segment is unavailable when the reason is not obvious.
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
export default function SegmentedControlStates() {
return (
<div className="gap-ws-12 flex flex-col items-start">
<SegmentedControl aria-label="Period" defaultValue="week">
<SegmentedControl.Item value="day">Day</SegmentedControl.Item>
<SegmentedControl.Item value="week">Week</SegmentedControl.Item>
<SegmentedControl.Item value="month" disabled>
Month
</SegmentedControl.Item>
</SegmentedControl>
<SegmentedControl aria-label="Period" defaultValue="week" disabled>
<SegmentedControl.Item value="day">Day</SegmentedControl.Item>
<SegmentedControl.Item value="week">Week</SegmentedControl.Item>
<SegmentedControl.Item value="month">Month</SegmentedControl.Item>
</SegmentedControl>
</div>
);
}API reference
SegmentedControl
| Name | Description | Default |
|---|---|---|
aria-label | Accessible name of the group, e.g. `"View mode"`. Give the group a name with this or `aria-labelledby`. Defines a string value that labels the current element. string | — |
aria-labelledby | ID of a visible element that names the group. Use instead of `aria-label` when a heading or label is on screen. Identifies the element (or elements) that labels the current element. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
defaultValue | Initial selected value for uncontrolled usage. string | — |
onValueChange | Fired when the selected value changes. Receives the new value string. ((value: string) => void) | — |
size | Controls the height and padding of the control and its items. 'sm''md''lg' | 'md' |
value | Controlled selected value. Pair with `onValueChange` to handle updates. string | — |
variant | Layout variant — `regular` auto-sizes to content, `fullWidth` expands to fill the container. 'regular''fullWidth' | 'regular' |
Radix RadioGroup.Root is passed through to it. See Radix RadioGroup.Root.SegmentedControl.Icon
| Name | Description | Default |
|---|---|---|
icon* | Icon component from `@remixicon/react` to render inside the item. RemixiconComponentType | — |
<div> is passed through to it. See MDN: <div>.SegmentedControl.Item
| Name | Description | Default |
|---|---|---|
aria-label | Defines a string value that labels the current element. Accessible name for an icon-only item. string | — |
aria-labelledby | Identifies the element (or elements) that labels the current element. ID of the element providing the accessible name for an icon-only item. string | — |
children | Content rendered inside the component. ReactNode | — |
icon | Optional icon rendered before children. Use `SegmentedControl.Icon` as a child for icon + label combinations. Icon component from `@remixicon/react`. RemixiconComponentType | — |
size | 'sm''md''lg' | 'md' |
variant | 'regular''fullWidth' | 'regular' |
Radix RadioGroup.Item is passed through to it. See Radix RadioGroup.Item.Accessibility
- Each icon-only item needs
aria-labeloraria-labelledby; the item warns in the console without one. - The control is one tab stop. Arrow keys move focus and select a segment; Space selects the focused segment. Enter does not select. Segments are announced as radio options.
- Home and End move focus to the first or last enabled segment without changing selection.
- Name the control (
aria-label) when no visible heading says what it switches.
| Part | Renders | Description |
|---|---|---|
| SegmentedControlRenders no element | Radix RadioGroup.Root | A group of mutually exclusive radio options. |
| SegmentedControl.IconRenders no element | <div> | An icon rendered within `SegmentedControl`. |
| SegmentedControl.ItemRenders no element | Radix RadioGroup.Item | An individual item within `SegmentedControl`. |
import { SegmentedControl } from '@/components/ui/wideset/segmented-control/SegmentedControl';
<SegmentedControl aria-label="View" defaultValue="board">
<SegmentedControl.Item value="list">List</SegmentedControl.Item>
<SegmentedControl.Item value="board">Board</SegmentedControl.Item>
<SegmentedControl.Item value="calendar">Calendar</SegmentedControl.Item>
</SegmentedControl>