Slider
AlphaAn accessible range input with single and dual-thumb modes, step support, and ARIA value text.
Import
import { Slider } from "@compa11y/react";Usage
Example.tsx
import { useState } from "react";
import { Slider, Text } from "@compa11y/react";
// Single value
function VolumeSlider() {
const [volume, setVolume] = useState(50);
return (
<div>
<Text as="label" size="sm" weight="semibold">Volume: {volume}%</Text>
<Slider
value={volume}
onValueChange={setVolume}
aria-label="Volume"
/>
</div>
);
}
// Range slider
function PriceFilter() {
const [range, setRange] = useState([20, 80]);
return (
<div>
<Text as="label" size="sm" weight="semibold">
Price: ${range[0]} – ${range[1]}
</Text>
<Slider
value={range}
onValueChange={setRange}
min={0}
max={200}
step={5}
aria-label={["Minimum price", "Maximum price"]}
/>
</div>
);
}Features
- Single and range (dual-thumb) modes
- Step and min/max constraints
- Horizontal and vertical orientation
- aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext
- Keyboard: Arrow keys, Home, End, Page Up/Down
- CSS variable customization
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | number[] | - | Controlled value (number for single, [min, max] for range) |
onValueChange | (value: number | number[]) => void | - | Called when value changes |
min | number | 0 | Minimum value |
max | number | 100 | Maximum value |
step | number | 1 | Step increment |
disabled | boolean | false | Disables the slider |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Slider orientation |
aria-label | string | string[] | - | Accessible label(s) for the thumb(s) |
Keyboard Interactions
Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
| Key | Action |
|---|---|
| ArrowRight / ArrowUp | Increases the value by one step |
| ArrowLeft / ArrowDown | Decreases the value by one step |
| Home | Sets value to minimum |
| End | Sets value to maximum |
| PageUp | Increases by a large step |
| PageDown | Decreases by a large step |