Slider

Alpha

An 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

Slider component props
PropTypeDefaultDescription
valuenumber | number[]-Controlled value (number for single, [min, max] for range)
onValueChange(value: number | number[]) => void-Called when value changes
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step increment
disabledbooleanfalseDisables the slider
orientation'horizontal' | 'vertical''horizontal'Slider orientation
aria-labelstring | 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.
Keyboard shortcuts for Slider
KeyAction
ArrowRight / ArrowUpIncreases the value by one step
ArrowLeft / ArrowDownDecreases the value by one step
HomeSets value to minimum
EndSets value to maximum
PageUpIncreases by a large step
PageDownDecreases by a large step