[ Navigation ]
SegmentedControl
A single-choice switcher with a thumb that slides to the selected option. Works like a radio group.
2 examplesDark modeAccessible
Import#
import { SegmentedControl } from 'reusify-ui';When to use#
- Switching between views or filters of the same content: Day / Week / Month, List / Grid, Yes / Maybe / No.
- Use Tabs when each option has its own panel of content and a heading-like role.
Examples#
Basic#
Selected: week
const [view, setView] = useState('week');
<SegmentedControl
aria-label="Range"
value={view}
onChange={setView}
options={[
{ value: 'day', label: 'Day' },
{ value: 'week', label: 'Week' },
{ value: 'month', label: 'Month' },
]}
/>Sizes, pill and full width#
Plain strings work as options. pill rounds the track, fullWidth stretches options evenly, and options can carry icons or be disabled.
<SegmentedControl size="sm" options={['Yes', 'Maybe', 'No']} />
<SegmentedControl pill options={['New Users', 'Online Sales', 'Daily Sales']} />
<SegmentedControl
fullWidth
size="lg"
options={[
{ value: 'list', label: 'List', icon: <FiList /> },
{ value: 'grid', label: 'Grid', icon: <FiGrid /> },
{ value: 'calendar', label: 'Calendar', icon: <FiCalendar />, disabled: true },
]}
/>Used in designs#
SegmentedControl in real layouts: these 5 designs use it. Open one to try it and copy the code.
- Route calloutsTasks & workflow
- PerformanceDashboard widgets
- Employee spotlightDashboard widgets
- Mood check-inSocial & fitness
- Event detailsProductivity
API reference#
<SegmentedControl />
Other props (e.g. aria-label) go on the radiogroup element.
| Prop | Type | Default | Description |
|---|---|---|---|
options | Array<string | { value, label, icon?, disabled? }> | - | The choices. |
value / defaultValue | any | - | Controlled / initial value. Defaults to the first enabled option. |
onChange | (value) => void | - | Called when the selection changes. |
size | 'sm' | 'md' | 'lg' | 'md' | Height and text size. |
pill | boolean | false | Fully rounded track and thumb. |
fullWidth | boolean | false | Stretch to the container, options share the width. |
disabled | boolean | false | Disables every option. |
options-Array<string | { value, label, icon?, disabled? }>The choices.
value / defaultValue-anyControlled / initial value. Defaults to the first enabled option.
onChange-(value) => voidCalled when the selection changes.
size'md''sm' | 'md' | 'lg'Height and text size.
pillfalsebooleanFully rounded track and thumb.
fullWidthfalsebooleanStretch to the container, options share the width.
disabledfalsebooleanDisables every option.
Accessibility#
- role="radiogroup" with role="radio" items and aria-checked. Give it an aria-label.
- One tab stop; Arrow keys move and select, skipping disabled options and wrapping around.
- The thumb animation is turned off under prefers-reduced-motion.