Slider
A slider selects a value, or a range of values, by dragging a thumb along a track. Arrow keys nudge the value and Home/End jump to the bounds, so the control is fully operable without a pointer.
The component is composed from parts. <Slider> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Slider>.
Interactive Preview
Section titled “Interactive Preview”import { Slider, SliderLabel, SliderControl, SliderTrack, SliderRange, SliderThumb,} from "@/components/ui/slider";
export function VolumeSlider() { return ( <Slider defaultValue={[40]} min={0} max={100} step={5}> <SliderLabel>Volume</SliderLabel> <SliderControl> <SliderTrack> <SliderRange /> </SliderTrack> <SliderThumb index={0} /> </SliderControl> </Slider> );}<script lang="ts"> import Slider from "@/components/ui/slider.svelte"; import SliderLabel from "@/components/ui/slider-label.svelte"; import SliderControl from "@/components/ui/slider-control.svelte"; import SliderTrack from "@/components/ui/slider-track.svelte"; import SliderRange from "@/components/ui/slider-range.svelte"; import SliderThumb from "@/components/ui/slider-thumb.svelte";</script>
<Slider defaultValue={[40]} min={0} max={100} step={5}> <SliderLabel>Volume</SliderLabel> <SliderControl> <SliderTrack> <SliderRange /> </SliderTrack> <SliderThumb index={0} /> </SliderControl></Slider>import { Slider, SliderLabel, SliderControl, SliderTrack, SliderRange, SliderThumb,} from "@/components/ui/slider";
export function VolumeSlider() { return ( <Slider defaultValue={[40]} min={0} max={100} step={5}> <SliderLabel>Volume</SliderLabel> <SliderControl> <SliderTrack> <SliderRange /> </SliderTrack> <SliderThumb index={0} /> </SliderControl> </Slider> );}Installation
Section titled “Installation”npx @glaceon/cli add slider --framework react # or svelte, solidData Attributes
Section titled “Data Attributes”| Attribute | Values | Applied to |
|---|---|---|
data-scope |
slider |
every part |
data-part |
root, label, control, track, range, thumb |
matching part |
data-dragging |
present / absent | thumb |
data-disabled |
present / absent | root, control, track, range, thumb |
data-orientation |
horizontal, vertical |
root and below |
The thumb element is a 44px hit area wrapping a 20px visual dot. Style the dot, not the thumb: giving the thumb a background shrinks the target to the visual size. The same applies to the control, which is a 44px lane that the finger lands on.
API Reference (Props)
Section titled “API Reference (Props)”| Part | Prop | Type | Description |
|---|---|---|---|
Slider |
children |
content | The root and its control |
Slider |
defaultValue |
number[] |
Initial value |
Slider |
value |
number[] |
Controlled value |
Slider |
min / max |
number |
Bounds |
Slider |
step |
number |
Increment per step |
Slider |
disabled |
boolean |
Prevents interaction |
Slider |
name |
string |
Name used in form submission |
Slider |
onValueChange |
(details) => void |
Called as the value changes |
SliderThumb |
index |
number |
Which thumb, for a range slider. Defaults to 0 |
Multiple thumbs work by rendering one <SliderThumb> per index under the same <SliderTrack>.
Every part also accepts className (React) or class (Svelte, Solid), merged with cn().
Keyboard Interactions
Section titled “Keyboard Interactions”| Key | Behaviour |
|---|---|
Arrow Right / Arrow Up |
Increases the value by one step |
Arrow Left / Arrow Down |
Decreases the value by one step |
Home |
Jumps to the minimum |
End |
Jumps to the maximum |
Accessibility
Section titled “Accessibility”role="slider", aria-valuenow, aria-valuemin, aria-valuemax and aria-orientation are managed by the Zag.js machine. The 44px hit area satisfies WCAG 2.2 SC 2.5.8 target size requirements.