Usage
By default, <Slider>
will display an uncontrolled input allowing a user to select a value between 0 (default) and 100. The value can be changed by dragging the thumb, clicking on the slider bar, or using arrow keys. You can initialize the starting value by passing in defaultValue
.
Controlled state
To control the value of the slider, set value
and onValueChange
.
Value: 25Commit Value: 25
Range
Provide multiple values to create a range slider.
Optionally, you can set a minimum step distance between the two selected values by passing minStepsBetweenThumbs
.
Vertical
To display a vertical slider, pass orientation="vertical"
. The slider will expand to fill the height of its parent.
Disabled
Sliders can be rendered non-interactive by setting the disabled
prop.
API Reference
Slider
Inherits properties from HTMLElement
.
Prop | Type | Default |
---|---|---|
asChild | boolean | false |
defaultValue | number[] | |
disabled | boolean | |
inverted | boolean | false |
max | number | 100 |
min | number | 0 |
minStepsBetweenThumbs | number | 0 |
name | string | |
onValueChange | (value: number[]) => void | |
onValueCommit | (value: number[]) => void | |
orientation | "horizontal" "vertical" | "horizontal" |
step | number | 1 |
value | number[] |