Slider
Pick a number, or a range, by dragging or with the keyboard.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on radix-ui/Slider
- Each thumb is role=slider with aria-valuenow, min and max.
- Arrow keys step; Home and End jump to the ends; PageUp and PageDown take larger steps.
- aria-label is required; a range labels its thumbs minimum and maximum.
- Styles in one file:
slider.css
Import
import '@monoline/css';
import {Slider} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add slider
It needs radix-ui; install it if your project does not have it:
npm install radix-ui
Usage
import {Slider} from '@monoline/react';
<div style={{display: 'grid', gap: 'var(--s5)', maxWidth: 420}}>
<Slider aria-label="Volume" defaultValue={60} />
<Slider aria-label="Price" defaultValue={[20, 70]} />
</div>
Examples
Single and range
Props
SliderProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | [number, number] | – | A number for one thumb, or [low, high] for a range. |
defaultValue | number | [number, number] | – | The starting value when uncontrolled: a number for one thumb or `[low, high]` for a range. Default 0. |
onValueChange | ((value: number[]) => void) | – | Called with an array holding the value of each thumb while the user drags or uses the keyboard. |
aria-label required | string | – | Accessible name for each thumb. One string for a single thumb, or [low, high] labels for a range. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-disabled] | slider.css |
[data-state="on"] | slider.css |
CSS classes
| Class | Stylesheet |
|---|---|
.slider | slider.css |
.slider-range | slider.css |
.slider-thumb | slider.css |
.slider-track | slider.css |
.toggle | slider.css |
.toggle-group | slider.css |
.progress | 12-range.css |
.range | 12-range.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
.slider {
border-color: var(--accent);
}
.slider[data-disabled] {
background: var(--wash);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
example.tsx
<Slider aria-label="Volume" defaultValue={40} />
Accessibility
- Each thumb is role=slider with aria-valuenow, min and max.
- Arrow keys step; Home and End jump to the ends; PageUp and PageDown take larger steps.
- aria-label is required; a range labels its thumbs minimum and maximum.
Keyboard
| Keys | Action |
|---|---|
| Arrow keys | Step |
| Home / End | Jump to the ends |
| PageUp / PageDown | Take larger steps |