Slider
FormRange input for selecting a numeric value within a min/max range. Supports single and dual thumbs.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { Slider } from "@dashboardpack/core/components/ui/slider";
import { useState } from "react";
export default function SliderExample() {
const [volume, setVolume] = useState([40]);
const [budget, setBudget] = useState([20, 80]);
return (
<div className="w-full max-w-sm space-y-8">
<div className="space-y-4">
<p className="text-sm">Volume: {volume[0]}%</p>
<Slider
aria-label="Volume"
ref={(root) => {
root
?.querySelector('[role="slider"]')
?.setAttribute("aria-label", "Volume");
}}
value={volume}
onValueChange={setVolume}
min={0}
max={100}
step={1}
/>
</div>
<div className="space-y-4">
<p className="text-sm">Budget: {budget.join(" – ")}</p>
<Slider
aria-label="Budget range"
ref={(root) => {
root
?.querySelectorAll('[role="slider"]')
.forEach((thumb, index) =>
thumb.setAttribute(
"aria-label",
index === 0 ? "Minimum budget" : "Maximum budget",
),
);
}}
value={budget}
onValueChange={setBudget}
min={0}
max={100}
step={5}
/>
</div>
<Slider
aria-label="Disabled slider"
ref={(root) => {
root
?.querySelector('[role="slider"]')
?.setAttribute("aria-label", "Disabled volume");
}}
disabled
defaultValue={[50]}
/>
</div>
);
}Usage
Pass an array containing one value for a single thumb or two values for a range. The default creates two thumbs; set defaultValue explicitly for a single-value slider.
import { Slider } from "@dashboardpack/core/components/ui/slider";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| value / defaultValue | number[]Default: [min, max] | Controlled or initial thumb positions. |
| onValueChange | (values: number[]) => voidDefault: — | Handle updates while dragging. |
| min / max | numberDefault: 0 / 100 | Allowed numeric bounds. |
| step | numberDefault: 1 | Step between values. |
| disabled | booleanDefault: false | Disable changes. |