Slider
Slider and RangeSlider components
Import
Source
Docs
Package
Usage
Controlled
Controlled Slider
:
Controlled RangeSlider
:
Disabled
onChangeEnd
onChangeEnd
callback is called when user the slider is stopped from being dragged or value is changed with keyboard.
You can use it as a debounced callback to avoid too frequent updates.
onChange value: 50
onChangeEnd value: 50
Control label
To change label behavior and appearance, set the following props:
label
– formatter function, accepts value as an argument, set null to disable label, defaults tof => f
labelAlwaysOn
– if true – label will always be displayed, by default label is visible only when user is dragginglabelTransitionProps
– props passed down to the Transition component, can be used to customize label animation
No label
Formatted label
Label always visible
Custom label transition
Min, max and step
Decimal step
Step matched with marks
Marks
Add any number of marks to slider by setting marks
prop to an array of objects:
Note that mark value is relative to slider value, not width:
Thumb size
Thumb children
Scale
You can use the scale
prop to represent the value on a different scale.
In the following demo, the value x
represents the value 2^x
. Increasing x
by one increases the represented value by 2 to the power of x
.
Inverted
You can invert the track with the inverted
prop:
Styles API
Slider
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Example of using Styles API to change Slider
styles:
Vertical slider
Slider
and RangeSlider
do not provide vertical orientation as it is very rarely used.
If you need this feature you can build it yourself with use-move hook.
Accessibility
Slider
and RangeSlider
components are accessible by default:
- Thumbs are focusable
- When the user uses mouse to interact with the slider, focus is moved to the slider track, when the user presses arrows focus is moved to the thumb
- Value can be changed with arrows with step increment/decrement
To label component for screen readers, add labels to thumbs:
Keyboard interactions
Key | Description |
ArrowRight/ArrowUp | Increases slider value by one step |
ArrowLeft/ArrowDown | Decreases slider value by one step |
Home | Sets slider value to min value |
End | Sets slider value to max value |