Slider

Pick a value or a range on a track that follows your finger.

npx shadcn@latest add @silicon-ui/slider
sliderrangeinput
Loading…

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/slider

Manually

  1. Install the dependencies.

    npm install motion
  2. Copy these files into your project. Shared files are skipped if you already have them.

    • components/silicon-ui/slider/slider.tsx
    • components/silicon-ui/slider/slider.module.css
  3. Install the foundation once per app for the design and motion tokens: npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

Source codetsx
import { Slider } from "@/components/silicon-ui/slider/slider";

API reference

PropTypeDefault
label*

Visible label. Range thumbs are named from it unless `thumbLabels` says otherwise.

string—
value

A number for one thumb, a pair for a range.

T—
defaultValueT—
onValueChange(value: T) => void—
onValueCommit

Runs once a drag is released or a key changes the value, for work too heavy for every step.

(value: T) => void—
minnumber0
maxnumber100
stepnumber1
largeStep

PageUp, PageDown, and Shift with an arrow move this far. Defaults to a tenth of the range.

number—
marks

Ticks on the track. A number draws a tick; a mark with a label also prints it under the track, and clicking it moves there.

(number | SliderMark)[]—
minStepsBetweenThumbs

The closest two range thumbs may sit, in steps.

number0
format

Formats the readout, the bubble, and the spoken value.

(value: number) => string—
showValue

Show the value beside the label. The bubble over the thumb still appears while dragging or focused.

booleantrue
thumbLabels

Accessible names for the two range thumbs.

[string, string]—
start

Content beside the track, such as an icon or a mute button.

ReactNode—
endReactNode—
name

Submits the value with a form, one hidden input per thumb.

string—
disabledboolean—
classNamestring—

Dependencies

npm
motion
Registry
silicon-motion-tokens