Slider
Adjust a value along a continuous or stepped range.
Volume: 40
Installation
Terminal
pnpm dlx shadcn@latest add https://react-toolbox.io/r/slider.jsonNew here? Set up your project first. Styles, fonts, and required components are included.
Usage
Use pinned to display the value and snaps to snap to step positions. Provide an accessible name with aria-label or aria-labelledby.
Composition
Compose multiple named thumbs with minStepsBetweenThumbs, or set orientation="vertical". Values, keyboard direction, and form inputs are managed by Radix.
Temperature: 16–26 °C
Show composition code
tsx
'use client';
import { useState } from 'react';
import { SliderRoot, SliderTrack, SliderRange, SliderThumb } from '@/components/ui/material/slider';
export default function SliderComposition() {
const [range, setRange] = useState([16, 26]);
return (
<div className="flex flex-wrap items-center gap-12">
<div className="w-64 max-w-full">
<p className="text-toolbox-body">
Temperature: {range[0]}–{range[1]} °C
</p>
<SliderRoot
name="temperature"
value={range}
onValueChange={setRange}
min={0}
max={40}
minStepsBetweenThumbs={2}
>
<SliderTrack>
<SliderRange />
</SliderTrack>
<SliderThumb aria-label="Minimum temperature" />
<SliderThumb aria-label="Maximum temperature" />
</SliderRoot>
</div>
<SliderRoot orientation="vertical" defaultValue={[50]} className="h-40">
<SliderTrack>
<SliderRange />
</SliderTrack>
<SliderThumb aria-label="Volume" />
</SliderRoot>
</div>
);
}
State and callbacks
- Use
value/onChange, ordefaultValuefor internal state and form reset.nameandformsubmit the numeric value. onChangereports live values. UseonValueCommitfor expensive work after a drag, keyboard change, or edited value is committed.onDragStart/onDragStoponly report pointer interaction.
API reference
Key props and defaults. Full types and inline documentation are included with the source in material/slider.
Slider
| Property | Type | Default |
|---|---|---|
defaultValue | number | 0 |
max | number | 100 |
min | number | 0 |
onChange | (value: number, event?: SyntheticEvent<HTMLInputElement | HTMLTextAreaElement>) => void | — |
onValueCommit | (value: number) => voidFires after a completed drag, keyboard change, or editable value commit. | — |
pinned | boolean | false |
step | number | 0.01 |
value | number | — |
Material guidelines
- Continuous sliders work well for subjective adjustments such as volume. Use a discrete slider with stops and a value label when choosing among fixed values.
- Keep the thumb’s larger interaction area even though its visible circle is smaller. Provide a meaningful label and keyboard adjustment.