Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.
Slider
An input where the user selects a value from within a given range.
Features
Can be controlled or uncontrolled.
Supports multiple thumbs.
Supports a minimum value between thumbs.
Supports touch or click on track to update value.
Supports Right to Left direction.
Full keyboard navigation.
Anatomy
Import all parts and piece them together.
API Reference
Root
Contains all the parts of a slider. It will render an input for each thumb when used within a form to ensure events propagate correctly.
Track
The track that contains the Slider.Range.
Range
The range part. Must live inside Slider.Track.
Thumb
A draggable thumb. You can render multiple thumbs.
Examples
Vertical orientation
Use the orientation prop to create a vertical slider.
Create a range
Add multiple thumbs and values to create a range slider.
Define step size
Use the step prop to increase the stepping interval.
Prevent thumb overlap
Use minStepsBetweenThumbs to avoid thumbs with equal values.
Decoupling the hidden input
By default, Slider.Thumb renders a visually hidden input for form submission. To recompose, move, or exclude that input, you can build each thumb from its lower-level parts instead.
Important: These parts are unstable and prefixed with
unstable_, so their API may change in a future release.
Slider.unstable_ThumbProviderprovides the thumb state and accepts an optionalnamefor the submitted value.Slider.unstable_ThumbTriggeris the draggable thumb element.Slider.unstable_BubbleInputis the visually hidden input thatSlider.Thumbrenders by default. Omit it when you don't need form submission.
Accessibility
Adheres to the Slider WAI-ARIA design pattern.
Keyboard Interactions
Custom APIs
Create your own API by abstracting the primitive parts into your own component.
Abstract all parts
This example abstracts all of the Slider parts so it can be used as a self closing element.
Usage
Implementation
Caveats
Mouse events are not fired
Because of a limitation we faced during implementation, the following example won't work as expected and the onMouseDown and onMouseUp event handlers won't be fired:
We recommend using pointer events instead (eg. onPointerDown, onPointerUp). Regardless of the above limitation, these events are better suited for cross-platform/device handling as they are fired for all pointer input types (mouse, touch, pen, etc.).