RangeSlider
RangeSlider component
Source
LLM docs
Docs
Package
Usage
Controlled
Uncontrolled
RangeSlider can be used with uncontrolled forms the same way as a native input element.
Set the name attribute to include range slider value in FormData object on form submission.
To control the initial value in uncontrolled forms, use the defaultValue prop.
Example usage of uncontrolled RangeSlider with FormData:
Disabled
Control label
To change the label behavior and appearance, set the following props:
label– formatter function, accepts value as an argument, set to null to disable the label, defaults tof => flabelAlwaysOn– if true, the label will always be displayed; by default the label is visible only when the user is dragginglabelTransitionProps– props passed down to the Transition component, can be used to customize the label animation
No label
Formatted label
Label always visible
Custom label transition
Min, max and step
Decimal step
Step matched with marks
Domain
By default, min and max values define the possible range of values.
The domain prop allows setting the possible range of values independently of the
min and max values:
Decimal values
To use RangeSlider with decimal values, set the min, max, and step props:
minRange
Use the minRange prop to control the minimum range between from and to values
in RangeSlider. The default value is 10. This ensures the thumbs must be at least
the specified distance apart:
Minimum range: 20 (thumbs must be at least 20 units apart)
Value: [30, 60] - Range: 30
maxRange
Use the maxRange prop to control the maximum range between from and to values.
This limits how wide the selection can be. By default, maxRange is set to Infinity:
Maximum range: 50 (selection cannot be wider than 50 units)
Value: [20, 80] - Range: 60
pushOnOverlap
The pushOnOverlap prop controls whether the thumbs should push each other when they overlap.
By default, pushOnOverlap is true. If you want to disable this behavior, set it to false.
Example of pushOnOverlap={false}:
Marks
Add any number of marks to the slider by setting the 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:
Inverted
You can invert the track with the inverted prop:
Hidden marks
Hidden marks allow you to snap to specific values without displaying them visually on the track.
This is useful when you want to create a "sticky" snapping behavior to certain values that
you don't want to show to the user. Use this feature together with restrictToMarks prop:
Hidden marks allow you to snap to specific values without displaying them visually. Current value: [25, 75]
Accessibility
RangeSlider component is 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: