Slider
A range input built on Radix UI with single/dual thumb, step marks, value tooltip, and Framer Motion spring animations.
Basic
A fully accessible range slider with single and dual-thumb support, step marks, value tooltip, and spring-animated thumb interactions.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add sliderpnpm dlx @work-rjkashyap/unified-ui add slidernpx @work-rjkashyap/unified-ui add sliderbunx @work-rjkashyap/unified-ui add sliderIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import {
Slider,
Button,
} from "@work-rjkashyap/unified-ui";Basic Usage
Pass an array to defaultValue for an uncontrolled slider. A single value renders one thumb; two values render a range.
{
/* Single thumb */
}
<Slider defaultValue={[50]} />;
{
/* Dual thumb range */
}
<Slider defaultValue={[20, 80]} />;Variants
| Variant | Use Case |
|---|---|
default | General purpose |
primary | Branded primary action |
success | Positive ranges (battery, score) |
danger | Warning thresholds (volume, risk level) |
Sizes
With Value Tooltip
Set showTooltip to display the current value above the thumb on hover or focus.
Step Marks
Enable showMarks to display tick marks at each step interval. Pair with step to control granularity.
Custom Marks with Labels
Pass a marks array for custom mark positions and labels.
<Slider
defaultValue={[50]}
min={0}
max={100}
marks={[
{ value: 0, label: "0" },
{ value: 25, label: "25" },
{ value: 50, label: "50" },
{ value: 75, label: "75" },
{ value: 100, label: "100" },
]}
/>Controlled
Use value and onValueChange for full programmatic control.
const [volume, setVolume] = useState([50]);
<Slider
value={volume}
onValueChange={setVolume}
min={0}
max={100}
step={1}
showTooltip
formatTooltip={(v) => `${v}%`}
/>;Range Slider
Two values in defaultValue (or value) create a dual-thumb range input.
const [range, setRange] = useState([20, 80]);
<Slider
value={range}
onValueChange={setRange}
min={0}
max={100}
showTooltip
formatTooltip={(v) => `$${v}`}
/>;Min / Max / Step
Control the numeric bounds and increment precision.
{
/* Volume 0–100, step 5 */
}
<Slider defaultValue={[50]} min={0} max={100} step={5} showMarks />;
{
/* Rating 1–5, step 1 */
}
<Slider defaultValue={[3]} min={1} max={5} step={1} showMarks showTooltip />;
{
/* Price range */
}
<Slider
defaultValue={[100, 500]}
min={0}
max={1000}
step={50}
formatTooltip={(v) => `$${v}`}
showTooltip
/>;Disabled
<Slider defaultValue={[40]} disabled />Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number[] | — | Controlled value array. |
defaultValue | number[] | [min] | Initial value for uncontrolled mode. |
onValueChange | (value: number[]) => void | — | Callback when value changes. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
step | number | 1 | Step increment. |
variant | "default" | "primary" | "success" | "danger" | "default" | Color variant for range and thumb. |
size | "sm" | "md" | "lg" | "md" | Size of the track and thumb. |
orientation | "horizontal" | "vertical" | "horizontal" | Orientation of the slider. |
showMarks | boolean | false | Show step mark ticks along the track. |
marks | SliderMark[] | — | Custom mark positions and labels (overrides showMarks). |
showTooltip | boolean | false | Show value tooltip on hover/focus. |
formatTooltip | (value: number) => string | String(v) | Custom tooltip value formatter. |
disabled | boolean | false | Disables the slider. |
className | string | — | Additional CSS classes on the root element. |
SliderMark
| Property | Type | Description |
|---|---|---|
value | number | Position of the mark on the track. |
label | ReactNode | Optional label rendered below the mark. |
Keyboard Navigation
| Key | Behavior |
|---|---|
Arrow Left | Decrease value by one step |
Arrow Right | Increase value by one step |
Arrow Down | Decrease value by one step |
Arrow Up | Increase value by one step |
Home | Set value to minimum |
End | Set value to maximum |
Page Down | Decrease value by a larger increment |
Page Up | Increase value by a larger increment |
Motion
- Thumb hover — Spring scale to
1.1(stiffness: 400, damping: 30). - Thumb drag — Spring scale to
1.2(stiffness: 400, damping: 25). - Tooltip —
fadeInFastpreset (opacity 0 → 1,y 4 → 0, 120ms). - All animations respect
prefers-reduced-motionviauseReducedMotion().
Accessibility
- Built on @radix-ui/react-slider with full ARIA compliance.
- Each thumb has
role="slider"witharia-valuenow,aria-valuemin,aria-valuemax, andaria-orientationautomatically managed by Radix. - Full keyboard navigation (arrow keys, Home, End, Page Up/Down).
- Thumb focus ring via
focus-visiblering classes. - Tooltip is hidden from the accessibility tree (
pointer-events-none).
Design Tokens
| Token | Usage |
|---|---|
--primary | Default/primary range fill |
--success | Success variant range fill |
--danger | Danger variant range fill |
--muted | Track background |
--border | Step mark color |
--radius-full | Track and thumb border radius |
--duration-fast | Thumb transition speed |