An input where the user selects a value from within a given range.
Installation
Install the packages
Add the shadcn/ui component
Animate it
The CLI finds your shadcn/ui components through components.json, swaps their primitive imports for Animate UI's and removes the CSS animation classes Motion replaces.
Usage
Import the primitive from Animate UI instead of Radix UI. Everything else stays the same.
import { Slider } from '@animate-ui/react/primitives/radix-ui';
export function Volume() {
return (
<Slider.Root defaultValue={[50]} max={100} step={1}>
<Slider.Track>
<Slider.Range />
</Slider.Track>
<Slider.Thumb aria-label="Volume" />
</Slider.Root>
);
}Coming from the @radix-ui/react-slider package? Use the subpath: import * as SliderPrimitive from '@animate-ui/react/primitives/radix-ui/slider'.
Animation
Animate UI v1 had no slider: it moves like v1's switch thumb.
- The pressed or dragged thumb stretches along the track: its width grows by 3/16 (a 16px thumb becomes 19px, v1's switch
pressedWidth), on a spring (stiffness 400, damping 32), and springs back on release. It's the thumb's real width, so its round ends stay round, and Radix UI centers it on its value, so it grows on both sides (along its height in a vertical slider). - A press on the track glides the thumb and the range to the new value on the same spring: as quick as v1's switch thumb, calmer (it goes about 1.5% past the value, where v1's switch thumb went about 4%). Radix UI positions them with layout: they jump to the new place, and a transform offset springs back (FLIP), so nothing animates
left. With a range slider, only the thumb that moves glides. - Dragging follows the pointer instantly, and keyboard changes are instant. Dragging right after a press cancels the glide: the thumb sits under the pointer.
- Under reduced motion, presses jump and nothing stretches.
API Reference
Every part takes exactly the props of Radix UI's Slider. Animate UI adds the animation props below.
Root, Track
Radix UI props only.
Range
Radix UI props, plus:
| Prop | Type | Default |
|---|---|---|
transition? | Transition | { type: 'spring', stiffness: 400, damping: 32 } |
Thumb
Radix UI props, plus:
| Prop | Type | Default |
|---|---|---|
transition? | Transition | { type: 'spring', stiffness: 400, damping: 32 } |
The pressed thumb also gets data-pressed. AnimateUIProvider's tempo scales these transitions with everything else.