Playground

Segmented control

Pick exactly one option from a short row, shown as joined segments.

  • Built on radix-ui/ToggleGroup
  • A named radio group; arrow keys move and select, Home and End jump.
  • One option is always selected: pressing the active one does nothing.
  • Styles in one file: segmented-control.css

Import

import '@monoline/css';
import {SegmentedControl} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add segmented-control

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {SegmentedControl} from '@monoline/react';

<SegmentedControl
  aria-label="Chart range"
  options={[{value: 'day', label: 'Day'}, {value: 'week', label: 'Week'}, {value: 'month', label: 'Month'}]}
  defaultValue="week"
/>

Examples

Basic

Props

SegmentedControlProps

PropTypeDefaultDescription
options requiredSegmentedOption[]–The segments to show, each with a `value`, a `label` and an optional `disabled`.
valuestring–The selected segment's `value` when controlled. Pair with `onValueChange`.
defaultValuestring–The segment selected at first when uncontrolled. Defaults to the first option.
onValueChange((value: string) => void)–Called with the new segment's `value` when the user picks a different one.
aria-label requiredstring–Names the control, for example "View".

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-state="on"]segmented-control.css

CSS classes

ClassStylesheet
.segmentsegmented-control.css
.segmentedsegmented-control.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.segment {
  border-color: var(--accent);
}
.segment[data-state="on"] {
  background: var(--wash);
}

Accessibility

  • A named radio group; arrow keys move and select, Home and End jump.
  • One option is always selected: pressing the active one does nothing.

Keyboard

KeysAction
Arrow keysMove and select
Home / EndJump