Skip to content
synccn

Slider

Single value or range, with keyboard steps and value bubbles.

64
Price range$40 – $180

Playground

Change the props and copy the code. The controls come from the component's TypeScript types.

Props

step1
import { Slider } from "@/components/ui/slider";<Slider defaultValue={[40]} aria-label="Volume" />

Installation

$ pnpm dlx shadcn@latest add @synccn/slider

First time in this project? Connect synccn with one command.

Usage

import { Slider } from "@/components/ui/slider";<Slider defaultValue={[20, 80]} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

Slider

Single value or range slider. Pass an array as value for a range.

  • value
    number[]

    Controlled value; two numbers make a range.

  • defaultValue
    number[]

    Default [50]

    Initial value when uncontrolled.

  • onValueChange
    (value: number[]) => void

    Called with the new value.

  • min
    number

    Default 0

    Lowest value.

  • max
    number

    Default 100

    Highest value.

  • step
    number

    Default 1

    Amount per step.

  • disabled
    boolean

    Prevents changes.

  • showValue
    boolean

    Default false

    Bubble with the value on hover and focus.

  • format
    (value: number) => React.ReactNode

    Default (v) => v

    Formats the bubble value.

  • aria-label
    string

    Accessible name.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • →or↑Increase by one step
  • ←or↓Decrease by one step
  • Page UporPage DownChange by a bigger step
  • HomeorEndJump to the minimum or maximum

Accessibility

  • Each thumb has role slider with aria-valuenow, min and max. Pass aria-label to name it.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: slider
  • ARIA attributes: aria-label, aria-valuemax, aria-valuemin, aria-valuenow
  • Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Home, End, PageUp, PageDown
  • Shows a visible focus ring for keyboard users