nori-ui

Slider

Continuous-value slider with single, range, or N-thumb selection, full keyboard nav, RTL, and orientation support.

4.4 kBgzipped

At a glance

  • value and defaultValue are always arrays — pass [n] for single-thumb, [low, high] for range, [a, b, c, ...] for multi-thumb pickers.
  • onChange fires continuously while dragging; onValueCommit fires once when the interaction ends.
  • Web pointer behavior: clicking the track moves the nearest thumb; dragging keeps the cursor captured even if it strays off the thumb.
  • Keyboard: arrow keys ±step (axis follows orientation; horizontal honors dir="rtl" and inverted), PageUp/Down ±10·step (or 10% of range), Home/End to min/max.
  • minStepsBetweenThumbs enforces a gap so adjacent thumbs can't overlap.
  • dir="rtl" flips the visual mapping for horizontal sliders so the higher value sits on the left.
  • Native: tap-to-position + keyboard work; long-press dragging is a future enhancement on RN.

Preview

Single thumb plus a two-thumb range. Drag, click the track, or tab to a thumb and use the arrow keys.

Direction:

Multi-thumb

Three or more thumbs work the same way as range. minStepsBetweenThumbs enforces a gap so adjacent thumbs can't pass each other.

Direction:

Vertical

Higher values sit at the top. Arrow Up / Arrow Down change the value (axis follows orientation).

RTL

dir="rtl" flips the visual mapping so the higher value sits on the left. Arrow Right then decreases the value, matching how a reader expects "right" to behave in the opposite reading direction.

Direction:

Disabled

Direction:

min, max, step

The slider's value space. min (default 0) and max (default 100) bound the legal range; step (default 1) is the increment that arrow-key changes and snap-on-drag honor. step must divide max - min cleanly — non-integer steps work for currency / fractional sliders.

<Slider defaultValue={[50]} min={0} max={100} step={5} />
<Slider defaultValue={[1.5]} min={0} max={5} step={0.25} />

orientation and length

orientation="horizontal" (default) lays the track left-to-right; vertical runs bottom-to-top. length sets the track size in pixels along its axis — width for horizontal, height for vertical.

<Slider orientation="vertical" length={200} defaultValue={[50]} />

disabled

Greys the track + thumb, blocks pointer + keyboard interaction, and forwards aria-disabled.

<Slider disabled defaultValue={[42]} />

onInteractionStart and onInteractionEnd

Bracket the user's drag / keyboard interaction. onInteractionStart fires once when the user begins driving the slider (pointer down, first arrow key); onInteractionEnd fires once when they stop. Pair with onChange (continuous, every step) and onValueCommit (final value at end of interaction) when the change is expensive enough to debounce.

<Slider
    defaultValue={[50]}
    onInteractionStart={() => analytics.track('slider:start')}
    onInteractionEnd={() => analytics.track('slider:end')}
    onValueCommit={(values) => save(values[0])}
/>

aria-label and ariaLabelForThumb

Slider tracks need an accessible name (aria-label or aria-labelledby on the slider). For multi-thumb sliders, label each thumb individually via ariaLabelForThumb — a function that receives the thumb's index and returns the label string.

<Slider
    aria-label="Price range"
    ariaLabelForThumb={(i) => i === 0 ? 'Minimum price' : 'Maximum price'}
    defaultValue={[20, 80]}
/>

Props

PropTypeDefaultDescription
aria-labelstringGroup-level accessibility label.
ariaLabelForThumb(thumbIndex: number) => stringPer-thumb label provider — `(index) => string`. Required for multi-thumb sliders to announce sensibly.
classNamestring
defaultValuereadonly number[]Uncontrolled initial value(s). @defaultValue [0]
direnumltrReading direction. Affects which end is min/max for horizontal sliders. @defaultValue 'ltr'
disabledbooleanfalseWhen true, the slider is non-interactive.
invertedbooleanfalseReverse the visual + interaction direction (useful for "less is more" sliders).
lengthnumber200Fixed track length when orientation="vertical". @defaultValue 200
maxnumber100@defaultValue 100
minnumber0@defaultValue 0
minStepsBetweenThumbsnumber0Multi-thumb spacing — minimum number of `step`s required between adjacent thumbs. @defaultValue 0
onChange(next: number[]) => voidFires continuously while a thumb moves.
onInteractionEnd() => voidFires when a pointer/touch releases (pair with `onInteractionStart`).
onInteractionStart() => voidFires when a pointer/touch starts driving the slider. Pair with `onInteractionEnd` to toggle a parent ScrollView's `scrollEnabled` — RN's responder system can't preempt UIScrollView's native pan recognizer on iOS, so the canonical fix is for the consumer to disable scroll while the user is actively dragging.
onValueCommit(next: number[]) => voidFires when interaction ends (pointer up, key release).
orientationenumhorizontal@defaultValue 'horizontal'
stepnumber1Step size. @defaultValue 1
testIDstring
valuereadonly number[]Controlled value(s). For a single-thumb slider pass `[n]`.

On this page

Preview theme