Slider
Choose a number or range by moving one or more thumbs.
Anatomy#
Usage#
Use Slider when a numeric value or range is best chosen spatially. Pair it with a labeled numeric field when users need precise text entry. Use NumberInput when the value is typed and stepped rather than dragged. Use BoldSlider for a compact single value with the label and value shown inside the track.
Single values and ranges#
Use a number for one thumb and an array for one thumb per entry, such as an ordered pair for a
range. Values are clamped to min–max (default 0–100), and arrays are sorted. Pair value
with onValueChange for controlled state, or use defaultValue for uncontrolled state; its shape
sets the shape of the value that callbacks receive.
onValueChange fires on every change during a drag, track click, or key press, but not for
programmatic changes to value. Use onValueCommit to react once when the interaction ends, such
as when saving a setting.
Step and markers#
Set step to snap pointer drag and keyboard navigation to multiples of it from min. Set markers
to true to draw a tick at each step (this requires a step above 0), or to a number to draw a
tick every that many units without changing how the value snaps.
Value text format#
formatOptions accepts Intl.NumberFormat options and formats each thumb’s aria-valuetext with
the provider locale. It does not change the value that callbacks receive. A percent style
multiplies by 100, so pair it with a 0–1 range. BoldSlider also uses formatOptions for its
visible value unless valueLabel is a formatter.
Forms#
Add name for native form submission, or place the slider inside form.Field from
createForm for schema binding. Use standalone Field when
you only need a label and messages.
Custom content#
Pass children to render extra content inside the root after the thumbs. A render function
receives the live value, sorted values, percentages from 0 to 1, dragging state, and the
startEdge where the filled range begins. Declare the function’s parameter even when you do not use
it; a zero-argument function is called as an accessor and is not mounted as a component.
Keyboard interaction#
When step is omitted, keyboard stepping defaults to 1% of the configured range. Page-sized
movement is approximately 10% of the range and is snapped to step when one is defined. Horizontal
arrow keys swap in right-to-left layouts, and a reversed vertical slider swaps ↑
and ↓.
| Key | Description |
|---|---|
| → / ↑ | Moves in the increasing direction by one keyboard step. |
| ← / ↓ | Moves in the decreasing direction by one keyboard step. |
| Shift + Arrow | Moves by the page-sized increment. |
| ⇞ / ⇟ | Moves by the page-sized increment. |
| ↖ | Moves the focused thumb to its minimum permitted value. |
| ↘ | Moves the focused thumb to its maximum permitted value. |
Examples#
Control output volume#
Keep a single number in local state and update it from onValueChange. Mute can write 0 back
into the same signal.
Set a numeric range#
Pass an ordered pair for two thumbs. minStepsBetweenThumbs and allowThumbCrossing constrain
whether the thumbs may overlap.
Bind brightness to a form#
Place the slider in form.Field so the schema owns the committed number.
Snap volume to ticks#
Set step so drag and keyboard land on increments. Enable markers to draw those ticks on the
track.
API Reference#
Attributes#
data-disableddata-draggingdata-invaliddata-multipledata-readonlydata-requireddata-reverseddata-swipe-ignoredata-emptydata-activedata-focus-visibleProps#
Props for the Slider component. Renders a <div> element by default.