Components
Slider
A range slider component for selecting numeric values
Slider
The Slider component provides a range input for selecting numeric values. Built on Radix UI primitives for full accessibility and smooth interactions.
Import
import { Slider } from '@nqlib/nqui';Basic Usage
import { Slider } from '@nqlib/nqui';
import { useState } from 'react';
export default function Example() {
const [value, setValue] = useState([50]);
return (
<Slider value={value} onValueChange={setValue} max={100} />
);
}Examples
Basic Slider
Range Slider
Custom Min/Max
Disabled State
With Steps
Controlled Slider
Use controlled state:
const [value, setValue] = useState([50]);
<Slider value={value} onValueChange={setValue} max={100} />Range Slider
Use an array of two values for range selection:
const [value, setValue] = useState([25, 75]);
<Slider value={value} onValueChange={setValue} max={100} />Custom Min/Max
Set custom minimum and maximum values:
<Slider min={0} max={100} step={10} />With Steps
Control the step increment:
<Slider step={5} max={100} />Disabled State
<Slider defaultValue={[50]} disabled max={100} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number[] | - | Controlled value array |
defaultValue | number[] | - | Uncontrolled default value array |
onValueChange | (value: number[]) => void | - | Callback when value changes |
min | number | 0 | Minimum value |
max | number | 100 | Maximum value |
step | number | 1 | Step increment |
disabled | boolean | false | Whether the slider is disabled |
orientation | "horizontal" | "vertical" | "horizontal" | Slider orientation |
className | string | - | Additional CSS classes |
Styling
Sliders use the following design tokens:
- Track:
bg-muted - Range:
bg-primary - Thumb:
bg-whitewithborder-primary - Focus ring:
ring-ring/30
Accessibility
- Full keyboard navigation support
- ARIA attributes for screen readers
- Focus management
- Proper label association
- Disabled state handling
Best Practices
- Always use labels: Provide clear labels indicating what the slider controls
- Show current value: Display the current value near the slider
- Use appropriate ranges: Set min/max values that make sense for your use case
- Consider steps: Use steps for discrete values (e.g., 0, 5, 10, 15)
- Handle disabled states: Clearly indicate when sliders are disabled
Next Steps
- Learn about Input for text inputs
- Explore Form Components for other form elements