codefast/ui

Command Palette

Search for a command to run...

Form

Slider

Range input with keyboard support. Supports min, max, step, and multiple thumbs.

Install

pnpm add @codefast/ui

Import path

@codefast/ui/slider

Examples

Range (two thumbs)

Pass an array of two values to get a min–max range, e.g. a price filter.

Controlled

An input where the user selects a value from within a given range.

0.3, 0.7

Disabled

Use the disabled prop to disable the slider.

Multiple Thumbs

Use an array with multiple values for multiple thumbs.

RTL

Right-to-left layout support for languages such as Arabic and Hebrew.

Translations are AI-generated for demonstration and may be imperfect.

Vertical

Use orientation='vertical' for a vertical slider.

Anatomy

How the parts compose. Copy this skeleton and fill in the slots.

import { Slider } from "@codefast/ui/slider";

// single
<Slider value={[60]} onValueChange={setValue} max={100} />

// range — two thumbs
<Slider value={[200, 700]} onValueChange={setRange} max={1000} />

API reference

Props for each part of the component. All native element props are also forwarded.

Slider

Built on Radix Slider. The number of thumbs follows the length of value.

PropTypeDefaultDescription
value / onValueChangenumber[] / (value: number[]) => voidControlled thumb positions. Two entries render a range.
defaultValuenumber[]Initial positions when uncontrolled.
min / maxnumber0 / 100Bounds of the track.
stepnumber1Granularity the thumb snaps to.
orientation"horizontal" | "vertical""horizontal"Axis of the slider.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

KeyFunction
TabMoves focus between thumbs.
Arrow+RightIncreases the focused thumb by one step.
Arrow+LeftDecreases the focused thumb by one step.
HomeSets the thumb to its minimum.
EndSets the thumb to its maximum.
  • Each thumb is a slider role with aria-valuenow / valuemin / valuemax set automatically.
  • Give the Slider an aria-label (or aria-labelledby) so the purpose is announced.
  • Pair with a visible readout so the current value is not conveyed by position alone.

Guidelines

Conventions that keep usage consistent across an app.

Do

  • Show the current value (or range) near the slider.
  • Pick a step that matches the precision users actually need.

Don’t

  • Don’t use a slider for precise numeric entry — use Input Number.
  • Don’t hide which thumb is which in a range without labels or a readout.