Slider
Picks a number or a range by dragging, with the value to read or type.
Installation
npm i @uisatin/uiimport { Slider } from '@uisatin/ui/slider'About 24.9 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/slider.jsonAdds slider.tsx, form-field.tsx, input.tsx, kbd.tsx, labels.tsx and tooltip.tsx to components/ui and installs radix-ui.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The Slider component wraps the Radix slider: one slider thumb for a number, two for a [from, to] range, with a hidden input per thumb when it has a name. The label names it; formatValue is what screen readers hear. Typed values in inputs are clamped, snapped to step and kept in order on Enter or blur.
| Prop | Type | Default |
|---|---|---|
value | number[number, number] | — |
defaultValue | number[number, number] | — |
onValueChange | (value: number | [number, number]) => void | — |
onValueCommit | (value: number | [number, number]) => void | — |
min | number | 0 |
max | number | 100 |
step | number | 1 |
minStepsBetweenThumbs | number | 0 |
label | ReactNode | — |
showValue | boolean | true |
inputs | boolean | false |
tooltip | boolean | false |
orientation | "horizontal""vertical" | "horizontal" |
formatValue | (value: number) => string | — |
disabled | boolean | false |
name | string | — |
className | string | — |
ref | Ref<HTMLElement> | — |
...props | ComponentProps<typeof Slider.Root>Other attributes go to the Radix Slider.Root part | — |
Accessibility
A Radix slider with a slider role per thumb, aria-valuemin, aria-valuemax, aria-valuenow and aria-valuetext from formatValue. One thumb is named by label (or aria-label); a range’s thumbs are named "From" and "To". The readout and the tooltip are hidden, since the thumbs say the value. The inputs are named "Value", or "From" and "To". Inside a form, hidden inputs carry the value.
| Key | Action |
|---|---|
| ←or→or↑or↓ | Moves the focused thumb one step. |
| Page UporPage Down | Moves it ten steps; Shift with an arrow does the same. |
| HomeorEnd | Moves it to min or max. |
| Enter | In an input: clamps the typed value, snaps it to step and commits it. |
| Esc | In an input: puts the current value back. |
Something wrong or missing on this page?
Report a problemSuggest an improvement