Overview
Get Started
Components
- Accordion
- Alert Dialog
- Alert
- Autocomplete
- Avatar
- Badge
- Button Group
- Button
- Calendar
- Checkbox Group
- Checkbox
- Collapsible
- Combobox
- Command
- Dialog
- Field
- Form
- Input Group
- Input
- Kbd
- Label
- Menu
- Meter
- Navigation Menu
- Number Field
- Number InputNew
- OTP Field
- Pagination
- Popover
- Radio Group
- Scroll Area
- Select
- Sheet
- Sidebar
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Tooltip
import { Slider } from "@/components/ui/slider";
export function SliderDemo() {
return <Slider defaultValue={50} className="max-w-xs" />;
}Installation
pnpm dlx @zbmui/cli@latest add slider
Usage
import { Slider } from "@/components/ui/slider";<Slider defaultValue={50} />Examples
Labeling a slider
Opacity
import { Slider, SliderLabel, SliderValue } from "@/components/ui/slider";
export function SliderDemo() {
return (
<Slider defaultValue={50} className="max-w-xs">
<div className="mb-2 flex items-center justify-between">
<SliderLabel>Opacity</SliderLabel>
<SliderValue />
</div>
</Slider>
);
}A single-thumb slider without a visible label (such as a volume control) can be labeled using aria-label on <SliderThumb> by passing thumbProps to <Slider>.:
<Slider defaultValue={50} thumbProps={[{ "aria-label": "Minimum price" }]}>
<SliderValue />
</SliderValue>A visible label can be created using <SliderLabel>:
<Slider defaultValue={50}>
<SliderLabel>Price range</SliderLabel>
<SliderValue />
</Slider>For a multi-thumb range slider with a visible label, add aria-label on each <SliderThumb> by passing thumbProps to <Slider> to distinguish them:
<Slider
defaultValue={[20, 80]}
thumbProps={[{ "aria-label": "Minimum price" }, { "aria-label": "Maximum price" }]}>
<SliderValue />
</Slider>Range slider
Price range
import { Slider, SliderLabel, SliderValue } from "@/components/ui/slider";
export function SliderDemo() {
return (
<Slider defaultValue={[10, 90]} className="max-w-xs">
<div className="mb-2 flex items-center justify-between">
<SliderLabel>Price range</SliderLabel>
<SliderValue />
</div>
</Slider>
);
}Vertical
import { Slider } from "@/components/ui/slider";
export function SliderDemo() {
return <Slider defaultValue={50} orientation="vertical" className="max-w-xs" />;
}Marks
0102030405060708090100
import { Slider, SliderValue } from "@/components/ui/slider";
const MIN = 0;
const MAX = 100;
const STEP = 10;
const MARKS = Array.from({ length: (MAX - MIN) / STEP + 1 }, (_, index) => {
const value = MIN + index * STEP;
return {
value,
percent: ((value - MIN) / (MAX - MIN)) * 100,
};
});
export function SliderDemo() {
return (
<div className="w-full max-w-xs">
<Slider
min={MIN}
max={MAX}
step={STEP}
defaultValue={50}
thumbAlignment="center"
thumbProps={[{ "aria-label": "Value" }]}
>
<div className="mb-2 flex items-center justify-end">
<SliderValue />
</div>
</Slider>
<div aria-hidden className="relative mt-2 h-8 select-none text-xs">
{MARKS.map(({ value, percent }) => (
<span
key={value}
className="absolute top-0 inline-flex -translate-x-1/2 flex-col items-center gap-1"
style={{ left: `${percent}%` }}
>
<span className="h-1.5 w-px bg-muted-foreground/60" />
<span>{value}</span>
</span>
))}
</div>
</div>
);
}