[ 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.

API reference#

<SegmentedControl />

Other props (e.g. aria-label) go on the radiogroup element.

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'md'
'sm' | 'md' | 'lg'

Height and text size.

pillfalse
boolean

Fully rounded track and thumb.

fullWidthfalse
boolean

Stretch to the container, options share the width.

disabledfalse
boolean

Disables 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.