compacto-ui

Search documentation

Jump to a page or a component.

Slider

Scalar slider on the progress anatomy; the thumb sits in the gap.

Preview

Descriptions75%
Descriptions100%
Temperature0.7

Installation

No install — ask an AI agent to copy this component from registry.json.

import { Slider, sliderVariants, sliderThumbVariants } from "@/components/ui/slider";

Notes

  • Scalar, unlike the Radix primitive underneath: value is a number and onValueChange hands you a number, not an array.
  • Single thumb only. The split geometry is positioned from one percentage, so a second thumb would have nowhere to put its gap — compose radix-ui's Slider directly for a two-handle range.
  • The thumb is a capsule sitting in the gap between fill and remainder. That gap is what keeps it legible against a fill in the same accent, with no ring in the surface colour to go wrong on a panel, a sidebar or a textured pane.
  • The capsule is dead centre in the gap at every value. Radix nudges a thumb inward near either end so it cannot overflow its track; that nudge is cancelled here with an opposite translateX, and the track is inset by a gap plus a pip at each end instead — at min the fill is a leading pip with the capsule one gap after it, at max the remainder is a trailing pip one gap past it.
  • Same anatomy as Progress, so a slider and a progress bar at the same value line up exactly.
  • Works controlled or uncontrolled; either way the component tracks the value itself, because the fill and remainder are placed from it.
  • onValueChange fires on every step while dragging, onValueCommit once at the end. Put the expensive write in the latter.
  • Horizontal only — no orientation prop.
  • Derives ${testId}-thumb, the one node a caller cannot otherwise reach.

Props

The props worth knowing. Everything else passes straight through to the underlying element, including className, which is merged last so it always wins.

PropTypeDefaultDescription
valuenumber—Current value, controlled form.
defaultValuenumberminStarting value, uncontrolled form.
onValueChange(value: number) => void—Every step while dragging.
onValueCommit(value: number) => void—Once, when the drag or key repeat ends.
min / max / stepnumber0 / 100 / 1Range and increment.
labelReactNode—Header copy, and the thumb's accessible name via aria-labelledby.
formatValue(value: number, max: number) => stringrounded percentageReadout string. Override for units — v.toFixed(1), `${v}px`.
size"sm" | "default" | "lg""default"Track height, gap, pip and thumb capsule.