Cognition

Components

Slider

An input where the user selects a value from within a given range. Drag a thumb along the track — use one thumb for a single value or two for a range, on either axis.

Preview

Volume50

Rendered with live Cognition tokens — the track, range fill, and thumb remap on theme change, no dark: classes. Drag the thumb to update the value.

Variants

<Slider defaultValue={[50]} max={100} step={1} />
<Slider defaultValue={[25, 75]} max={100} step={1} />
<Slider
  defaultValue={[50]}
  orientation="vertical"
  className="h-44"
/>
<Slider defaultValue={[40]} max={100} step={10} />

One thumb selects a value; two select a range. Set orientation="vertical" (with a height) to stand it up, and step to snap to coarser increments.

States

<Slider defaultValue={[50]} max={100} step={1} />
<Slider defaultValue={[40]} disabled />

The default slider is draggable and keyboard accessible (arrow keys move by step). A disabled slider dims to 50% and stops responding.

API

Prop
Type
Default
Description
defaultValue / value
number[]
[min, max]
Thumb positions. One entry = one thumb; two = a range. value makes it controlled (pair with onValueChange).
min
number
0
Lowest selectable value.
max
number
100
Highest selectable value.
step
number
1
Increment between stops as the thumb moves.
orientation
"horizontal" | "vertical"
"horizontal"
Axis. Vertical needs a height on the root (e.g. h-44).
disabled
boolean
false
Dims the slider to 50% and blocks interaction.
onValueChange
(value: number[]) => void
undefined
Fires as the thumb moves — use it to drive a controlled value.

Don't and Do

Don't

Don't use a slider when the exact value matters — a precise number is better typed into an Input. And don't hide the selected value; show it nearby so the user knows where they've landed.

Do
<Slider
  value={value}
  onValueChange={setValue}
  max={100}
  step={1}
/>
import { Slider } from "@/components/ui/slider";

export function VolumeSlider() {
  const [value, setValue] = useState([50]);
  return (
    <Slider value={value} onValueChange={setValue} max={100} step={1} />
  );
}
API matches fe-distillery/components/ui/slider.tsx — a single Slider built on Radix. The raw bg-primary track and thumb are replaced with Cognition tokens, and thumb rendering is extended to support range and vertical orientation.