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 => flabelAlwaysOn– 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
Decimal values
To use Slider with decimal values, set min, max and step props:
minRange
Use minRange prop to control minimum range between from and to values
in RangeSlider. The default value is 10. The example below shows how to
use minRange prop to capture decimal values from the user:
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:
Restrict selection to marks
Set restrictToMarks prop to restrict slider value to marks only. Note that in
this case step prop is ignored:
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.
Build custom slider
If Slider component does not meet your requirements, you can build a custom slider 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: