Inputs
Slider and RangeSlider
When to use
- The value is naturally perceived as a position on a scale: volume, opacity, a numeric filter.
- For a range you need two ends and, if necessary, a minimum gap
minGap. - Use a vertical
Sliderwhen the value reads as a level: volume, gain, fill. Several such sliders side by side form a control panel.
When not to use
- For precise input of a value without a visual scale, use
NumberInput. - For one of several discrete text options, use
Select/RadioGroup. - Do not put a vertical
Sliderin a form to save width: in a column of fields a horizontal one fits in with its neighbors, while a vertical one looks like a layout mistake. - There is no vertical
RangeSlider; itsorientationis rejected at the type level.
Minimal example
<Slider label="Opacity" value={opacity} onChange={setOpacity} minValue={0} maxValue={100} />
<RangeSlider label="Price" value={price} onChange={setPrice} minValue={0} maxValue={1000} minGap={50} />
<Slider label="Level" orientation="vertical" value={level} onChange={setLevel} formatValue={(v) => `${v}%`} />Public API
- The props inherit from React Aria Slider:
value/defaultValue,onChange,minValue,maxValue,step,isDisabled. labelnames the control;valuePositionisside(the default) ornone;formatValueformats the value for screen readers.Slider.orientationishorizontal(the default) orvertical.RangeSliderhas no such prop.RangeSlider.minGapprevents a range smaller than the specified gap. If the initial values already violateminGap, on the next change the component moves the end the user did not touch; the one under the finger stays in place.- With
minGap, keepRangeSlidercontrolled (value+onChange). In an uncontrolled one the clamped pair goes only toonChange, while the internal react-aria state stays unclamped: on the screen the ends can end up closer thanminGapeven though the correct value was passed toonChange. The kit cannot fix this on its side — the library holds that state.
Vertical Slider
- The range grows from the bottom edge: "more" on a vertical scale is higher.
- The height is set by the root:
h-48by default; set a custom height throughclassName(className="h-64"). Without a height a vertical track has nothing to stretch into. - The label and the value sit above the track, as on the horizontal one;
valuePositionandformatValuework the same. The slider width follows the width of the header (the label and the value above the track), not the full width of the container. - Why
RangeSliderhas no vertical orientation: the range geometry between two ends along the height is not implemented, and a prop that compiles and does nothing is worse than a missing one. If it is needed, it is a separate task.
Accessibility and keyboard
- React Aria implements pointer/touch, arrow keys (one step at a time), Shift for a large step and Home/End for the bounds.
- The mouse wheel and the touchpad over the slider move the value by a step: up increases, down decreases (on a horizontal one a sideways scroll to the right also increases). In
RangeSliderthe end nearest to the cursor moves, takingminGapinto account. At the edge of the scale the wheel event goes to the page, so that scrolling does not "stick" on the slider; withisDisabledthe slider ignores the wheel entirely. - On a vertical one the thumb announces
aria-orientation="vertical"; Up Arrow increases the value, Down Arrow decreases it. - With
isDisabledthe slider is dimmed as a whole — label, value, track and thumb — like the other kit fields; it cannot be dragged or focused. - Do not hide the value unless there is another clear display next to it.
- See
src/components/inputs/Slider.tsx,src/components/inputs/Slider.stories.tsx,tests/slider.test.tsx.
TypeScript types
SliderProps
Prop
Type
Plus DOM attributes, such as onClick, id, aria-label — 74 in total; the table does not repeat them.
RangeSliderProps
Prop
Type
Plus DOM attributes, such as onClick, id, aria-label — 74 in total; the table does not repeat them.