Slider
FreeNewA slider and range slider with a thumb that swells on drag and a springy value bubble.
Installation
pnpm dlx shadcn@latest add @viewport/slider
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
"use client";
import { useState } from "react";
import { Slider } from "@/components/viewport/slider";
const usd = (value: number) => `$${value.toLocaleString("en-US")}`;
export default function SliderDemo() {
const [seats, setSeats] = useState([12]);
const [budget, setBudget] = useState([400, 1600]);
return (
<div className="w-full max-w-sm space-y-8 rounded-2xl border border-border bg-card p-6">
<div>
<div className="mb-4 flex items-baseline justify-between">
<span className="text-sm font-medium">Seats</span>
<span className="text-sm tabular-nums text-muted-foreground">{seats[0]} people</span>
</div>
<Slider label="Seats" value={seats} onValueChange={setSeats} min={1} max={50} />
</div>
<div>
<div className="mb-4 flex items-baseline justify-between">
<span className="text-sm font-medium">Monthly budget</span>
<span className="text-sm tabular-nums text-muted-foreground">
{usd(budget[0])} – {usd(budget[1])}
</span>
</div>
<Slider label="Monthly budget" value={budget} onValueChange={setBudget} min={0} max={2000} step={50} minStepsBetweenThumbs={2} formatValue={usd} />
</div>
</div>
);
}Props
| Prop | Type | Default |
|---|---|---|
| label* | stringAccessible name. With two thumbs they are announced as "label, minimum" and "label, maximum". | — |
| showValue | booleanShow the value above the thumb on hover, focus and while dragging. | true |
| formatValue | (value: number) => stringFormats the value for the bubble and for screen readers, e.g. `(v) => `$${v}``. | String |
Accessibility
- Built on Radix Slider: arrow keys, Page Up and Down, Home and End.
- Each thumb is named, and formatted values are read through aria-valuetext.
- The bubble also shows on keyboard focus.