@akhatmirzo/ui

Slider

Pick a number or a range by dragging — one or two thumbs, marks, a value bubble and Field integration.

Import

import { Slider } from '@akhatmirzo/ui';

When to use

  • When the exact number doesn't matter — volume, brightness, radius. Users pick "roughly" and see the result right away.
  • Range filters — price "from — to", age, area. A two-thumb slider is faster than two inputs.
  • When users need an exact value (an amount, a quantity), an Input or MaskedInput works better — or put one next to the slider.
  • With only a few steps (3–5 options), a SegmentedControl or a RadioGroup is clearer.

The value is always an array

Like Radix, the value is always number[]: one thumb — [50], a range — [20, 80]. The number of thumbs comes from the array length. Without defaultValue the slider starts at [min].

<Slider defaultValue={[50]} />
<Slider defaultValue={[20, 80]} />

Range

Two values — two thumbs. formatValue formats the value in the bubble and for screen readers; minStepsBetweenThumbs sets the minimum distance between thumbs (in steps).

Narx: 1 000 000 so'm — 3 500 000 so'm

Value bubble

showValue controls the value shown above the thumb (styled like a Tooltip):

ValueVisible when
active (default)Hovered, dragged or focused
alwaysAlways
neverNever

Marks

marks draws ticks and labels under the track. Marks are visual only — step is what limits the value.

Sizes and states

size — md (6px track, 20px thumb, default) or sm (4px / 16px). The thumb's hit area is at least 40px in both sizes. disabled blocks dragging and focus.

With Field

Inside a Field the label names the thumb, the description and error are linked through aria-describedby, and an error switches the slider to the invalid state (red thumb and fill).

Do'kondan necha km uzoqlikkacha yetkazasiz

40 km dan uzoqqa kuryer yo'q

Vertical

orientation="vertical" makes the slider fill its parent's height (at least 160px). ↑ ↓ work on the keyboard too.

Forms and APIs

  • With name, each thumb renders a hidden <input> inside a <form>: name for one thumb, name[] for a range.
  • onValueChange fires on every move; onValueCommit fires once when dragging ends (or on a keyboard change). Hook server requests to onValueCommit.
<Slider
  defaultValue={[20]}
  onValueChange={setPreview} // on every move
  onValueCommit={(v) => saveSettings({ volume: v[0] })} // on release
/>

Props

Other <span> attributes and Radix Root props (dir, form) are passed through; ref points to the root element.

PropTypeDefaultDescription
valuenumber[]—Value (controlled mode)
defaultValuenumber[][min]Initial value
onValueChange(value: number[]) => void—On every change
onValueCommit(value: number[]) => void—When dragging ends or on a keyboard change
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step
minStepsBetweenThumbsnumber0Minimum distance between thumbs, in steps
orientation'horizontal' | 'vertical''horizontal'Direction
size'sm' | 'md''md'Track 4 / 6px, thumb 16 / 20px
showValue'never' | 'active' | 'always''active'Value bubble above the thumb
formatValue(value: number) => stringStringText for the bubble and aria-valuetext
marks{ value: number; label?: ReactNode }[]—Marks under the track
disabledboolean—Disables the slider
invalidboolean—Error state (automatic inside Field)
namestring—For forms: a hidden input per thumb (name[] for a range)
labels{ thumb?: (index: number, count: number) => string }'Qiymat' | 'Minimal qiymat' / 'Maksimal qiymat'Screen reader names of the thumbs
aria-labelstring—Slider name without a Field (combined with the thumb name in a range)

Data attributes

AttributeWhereValue
data-sizerootsm · md
data-orientationroot, track, thumbhorizontal · vertical
data-disabledroot, track, thumbpresent when disabled
data-invalidrootpresent in error state
data-slottrack, fill, ...slider-track · slider-range · slider-thumb · slider-value · slider-marks

Keyboard

KeyAction
← ↓ / → ↑Decrease / increase by one step
PageDown / PageUpDecrease / increase by 10 steps
Shift + arrow10 steps
Home / Endmin / max
TabMove to the next thumb

Accessibility

  • Role. Each thumb is role="slider" with aria-valuemin, aria-valuemax, aria-valuenow and aria-orientation. Built on Radix Slider.
  • Value text. aria-valuetext is the formatValue result, so screen readers say "1 500 000 so'm" instead of "1500000".
  • Name. Inside a Field the thumb is linked to the label via aria-labelledby. In a range each thumb is named label + "Minimal qiymat" / "Maksimal qiymat" (change it with labels.thumb). Without a Field, pass aria-label.
  • Errors. The Field's description and error go to aria-describedby, the error state to aria-invalid.
  • The bubble and marks are decorative — aria-hidden (the value is already in aria-valuetext).
  • Touch. The thumb has an invisible hit area of at least 40px.

On this page