Segmented control
Pick exactly one option from a short row, shown as joined segments.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
options required | SegmentedOption[] | – | The segments to show, each with a `value`, a `label` and an optional `disabled`. |
value | string | – | The selected segment's `value` when controlled. Pair with `onValueChange`. |
defaultValue | string | – | 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 required | string | – | Names the control, for example "View". |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-state="on"] | segmented-control.css |
CSS classes
| Class | Stylesheet |
|---|---|
.segment | segmented-control.css |
.segmented | segmented-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
| Keys | Action |
|---|---|
| Arrow keys | Move and select |
| Home / End | Jump |