Range sliderPro
Two-thumb range with value bubbles and an optional live histogram.
pnpm dlx shadcn@latest add @lode/range-sliderPrice per night
219 stays
When to use
- Filtering by a range: price, dates as numbers, sizes, scores.
When not to use
- One value: use a slider.
- Exact numbers: add inputs beside it.
Installation
pnpm dlx shadcn@latest add @lode/range-sliderPro components need an API key and the registry in components.json. See CLI and API keys.
1Install the dependencies
npm install motion2Copy the source into your project
Usage
Import it from @/components/ui/range-slider after installing.
import * as React from "react";
import { RangeSlider } from "@/components/ui/range-slider";
export function PriceFilter() {
const [range, setRange] = React.useState<[number, number]>([100, 400]);
return <RangeSlider aria-label="Price" min={0} max={600} step={10} value={range} onValueChange={setRange} format={(n) => `$${n}`} histogram={counts} />;
}API reference
RangeSlider
Two thumbs on one track, with bubbles while active and an optional histogram.
value / defaultValue / onValueChange
[number, number]
Controlled or uncontrolled.
onValueCommit
([number, number]) => void
Once per drag end or key press.
min / max / step / minGap= 0 / 100 / 1 / 0
number
Range, snapping and minimum distance between thumbs.
format= String
(n) => string
Labels and aria-valuetext.
histogram
number[]
Bars spread evenly across the range; bars inside the selection highlight.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange | [number, number] | – | Controlled or uncontrolled. |
| onValueCommit | ([number, number]) => void | – | Once per drag end or key press. |
| min / max / step / minGap | number | 0 / 100 / 1 / 0 | Range, snapping and minimum distance between thumbs. |
| format | (n) => string | String | Labels and aria-valuetext. |
| histogram | number[] | – | Bars spread evenly across the range; bars inside the selection highlight. |
Keyboard interactions
| Keys | Action |
|---|---|
| ←or↓ | Decrease the focused thumb |
| →or↑ | Increase |
| Page UporPage Down | 10% steps |
| HomeorEnd | Min or max |
Accessibility
- Each thumb is a labelled slider ("Price minimum", "Price maximum") whose limits respect the other thumb.
- Clicking the track moves the nearest thumb and focuses it.
Motion
- Histogram bars grow in a wave and change color as the range moves; thumbs grow while active; bubbles pop above them.
Responsive behavior
- Fills its container; touch drags work anywhere on the track.
Performance
- Drags use window listeners and only update the two values.
Notes for AI
- Fetch results in onValueCommit, not onValueChange.
This page as Markdown, for assistants and coding agents:
/components/range-slider/markdownThe full library index for assistants is at /llms.txt.
Related
Lode·229 doc pages·llms.txt