InputRange
InputRange is a slider for one number between min and max, operated by mouse, touch and keyboard. The thumb is an
ARIA slider, so it always needs a name: a visible label, or aria-label / aria-labelledby.When to use
Usage
<InputRange aria-label="Price" min={0} max={200} value={price} onChange={setPrice} />Defaults are min={0}, max={100}, step={1}, value={50}. Both events receive the number. onInput fires on every
step change; onChange is the committed value, debounced 100 ms while dragging and immediate on a key press. Neither
fires when the value does not change.
Stepped scale
mark draws a dot per step; markLabel prints getLabelValue(n) under each, bolding the picked one. label adds a
header row that names the slider, and showValue prints the value at its end instead of the floating bubble.
const LEVELS = ['lenient', 'conv', 'std', 'strict', 'crit'];
<InputRange
label="Alignment"
showValue
mark
markLabel
max={4}
value={level}
getLabelValue={(n) => LEVELS[n]}
onChange={setLevel}
/>;Gradient
gradient paints the track from the feedback tokens (danger → warning → success), so themes and presets retint
it. gradient="descending" reverses it for metrics where lower is better. Skip it for scales with no good end.
<InputRange aria-label="Risk" gradient="descending" mark markLabel step={25} getLabelValue={(n) => `${n}%`} />Inside a Field
Field names the slider with aria-labelledby pointing at its label. For the header row
instead, set hideLabel on the Field and pass label in inputProps.
<Field
component={InputRange}
name="effort"
label="Effort"
inputProps={{ mark: true, markLabel: true, min: 0, max: 3, getLabelValue }}
/>Accessibility
- The thumb has
aria-valuemin,aria-valuemax,aria-valuenowandaria-valuetextfromgetLabelValue. ←/↓and→/↑move onestep;PageDown/PageUpmove a tenth of the range;Home/Endjump to the ends.- It is one tab stop with a
:focus-visibleoutline; a press on the track moves the thumb there and focuses it. - Under a coarse pointer the thumb grows and the bubble sits higher, clear of the finger.
Properties
aria-labelstringnonearia-labelledbystringnonedisabledbooleannonegetLabelValue((n: number) => string)nonegradientbooleanSliderGradientDirectionnoneidstringnonelabelReactNodenonemarkbooleannonemarkLabelbooleannonemaxnumber100minnumber0onChange((v: number) => void)noneonInput((v: number) => void)noneshowValuebooleanfalsestepnumber1valuenumber50