Slider
Selects a number, or a range, by dragging a thumb along a track, for values where an approximate position is enough.
Limite de confiança40%
orientation
<Slider orientation="horizontal" />The slider has no built-in label or value readout. Place a label and the current value next to it, as the examples do.
When to use
- To set a threshold or a limit where the exact number matters less than the position, such as the minimum confidence of an extractor.
- To select a range between two values, such as a case value range.
- When the user benefits from seeing the minimum and maximum of the scale.
When not to use
- An exact number the user already knows. Use an Input with a number type.
- A choice between a few named options. Use Radio group.
- An on or off setting. Use Switch.
- A date interval. Use a date range picker.
Examples
Single value
Pair the slider with a label and the current value.
Confiança mínima do extrator80%
Range
Pass two numbers in value to get two thumbs.
Faixa de valor da causa (R$ mil)20 – 70
States
Confiança mínima do extrator60%
Content
- Name what the value controls: “Confiança mínima do extrator”, not “Valor”.
- Show the unit next to the value: “80%”, “R$ 20 – 70 mil”.
- Use
stepto match the precision people need. A step of5is easier to hit with a mouse than1.
Accessibility
- Built on Radix Slider. Each thumb has
role="slider"witharia-valuemin,aria-valuemax,aria-valuenowandaria-orientation. - Keyboard: arrow keys change the value by
step,Page UpandPage Downby larger steps, andHomeandEndjump to the minimum and maximum. - A single thumb needs an accessible name, and the component does not provide one. See Known issues.
onValueCommitfires once when the user releases the thumb. Use it to save, and useonValueChangeonly to update the interface while dragging.
Code
import { Slider } from "@repo/ui/slider";
const [value, setValue] = useState([80]);
<Slider max={100} min={0} onValueChange={setValue} step={5} value={value} />;
Props
Slider| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables dragging and keyboard input |
max | unknown | 100 | Highest value on the track |
min | unknown | 0 | Lowest value on the track |
onValueChange | (value: number[]) => void | — | Called on every change while dragging |
onValueCommit | (value: number[]) => void | — | Called once when the user releases the thumb |
orientation | "horizontal" | "vertical" | horizontal | Direction of the track |
step | unknown | 1 | Distance between selectable values |
value | number[] | — | Controlled value. One number per thumb; two numbers make a range |
Every other prop of the Radix Slider root, such as name, inverted and
minStepsBetweenThumbs, is forwarded.
Known issues
| Issue | Effect |
|---|---|
aria-label and aria-labelledby are spread on the root, but Radix reads the name from the thumb. The thumb is rendered without it. |
A single-thumb slider has no accessible name. Screen readers announce only “slider” and the value. |
| With two thumbs Radix names them “Minimum” and “Maximum” in English. | The package cannot be translated by apps, and the names do not say what the range measures. |
The thumb is h-3 w-3 (12px). |
Below the 24px minimum hit target. Hard to grab with a mouse on older screens. |
The thumb styles disabled with disabled:opacity-50, but the thumb is a span, so :disabled never matches. Radix sets data-disabled. |
A disabled slider looks identical to an enabled one. |
Range and Track both use border-secondary and the range has no fill. |
The selected portion cannot be told apart from the rest of the track. |
The focus ring uses ring-ring and ring-offset-background. The Tailwind config only defines old-ring and old-background. |
Neither class generates a style. The ring color and the offset fall back to Tailwind defaults. |