Slider
A track with a thumb to drag. For a number where feeling «a bit more, a bit less» matters more than typing the exact figure. The value is always written beside it.
import { Slider } from '@sypnia/ui/react'
With a unit, saved on release
The number follows the thumb; «Saved» appears only when it is let go.
Saved: 40 GB. Uploads stop when the project reaches it.
Code
import { useState } from 'react';
import { Field, Slider } from '@sypnia/ui/react';
export default function Units() {
const [saved, setSaved] = useState(40);
return (
<Field label="Storage limit" hint={`Saved: ${saved} GB. Uploads stop when the project reaches it.`}>
<Slider defaultValue={40} min={10} max={200} step={10} formatOptions={{ style: 'unit', unit: 'gigabyte' }} onChangeEnd={setSaved} />
</Field>
);
} Disabled
It keeps its value in sight and says why it cannot be moved.
Replicas come with the Pro plan.
Code
import { Field, Slider } from '@sypnia/ui/react';
export default function States() {
return (
<Field label="Read replicas" hint="Replicas come with the Pro plan.">
<Slider disabled defaultValue={1} max={5} />
</Field>
);
} When to use it
Use it when
- The value is a matter of degree inside a known range: a sample rate, a volume, a zoom, a share.
- The effect is seen at once while dragging. Save on
onChangeEnd, when the person lets go.
Do not use it when
- The exact figure matters or the range is huge: NumberInput.
- There are only a handful of stops with names (low, medium, high): SegmentedControl or RadioGroup.
- It shows progress and the person cannot change it: Progress or Meter.
For everyone
- Left and right arrows move one step; Page Up and Page Down move more; Home and End go to the ends.
- It is announced as a
sliderwith its name, its value written with its unit, and its limits. - The thumb is the only thing that carries the light, and on paper it has an ink ring. Its touch area is 44 px even though it looks smaller.
- A slider cannot be «wrong»: if a value is not allowed, set
min,maxandstepso it cannot be reached.
Props
| Slider | Type | Default |
|---|---|---|
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | number | |
disabled | boolean | |
formatOptionsHow the value is written beside the track, as in Intl.NumberFormat: `{ style: 'percent' }`, `{ style: 'unit', unit: 'gigabyte' }`. | NumberFormatOptions | |
idInside a Field it comes from the Field. | string | |
max | number | |
min | number | |
onChangeCalled while the thumb moves. | ((value: number) => void) | |
onChangeEndCalled once, when the person lets go: the moment to save. | ((value: number) => void) | |
step | number | |
value | number |