Slider

A control that allows the user to select a value or a range of values along a track.

Installation

Add this component to your project using the npui CLI:

npx npui add slider

Variants & Examples

Default Slider

A basic slider for selecting a single value.

1import { Slider } from "@/components/ui/slider"
2
3export function DefaultSlider() {
4  return <Slider defaultValue={[50]} max={100} step={1} className="w-[60%]" />
5}

Range Slider

A slider for selecting a range of values.

1import { Slider } from "@/components/ui/slider"
2
3export function RangeSlider() {
4  return <Slider defaultValue={[25, 75]} max={100} step={1} className="w-[60%]" />
5}

Props

These are the available props for the Slider component:

PropTypeDescriptionDefault
defaultValuenumber[]The initial value of the slider.-
valuenumber[]The controlled value of the slider.-
onValueChange(value: number[]) => voidEvent handler called when the value changes.-
maxnumberThe maximum value of the slider.100
minnumberThe minimum value of the slider.0
stepnumberThe step increment for the slider.1
disabledbooleanWhether the slider is disabled.false