Forms
Slider
Picks a number in a range by dragging a thumb.
Example
A slider suits values where the position in the range matters more than the exact number (volume, rough budget). For a precise value, prefer a text field of type number.
min (0 by default), max (100) and step (1) bound the value. A bubble follows the thumb showing the value, formatted for the page language, and grows while dragging or on keyboard focus; the filled part of the track follows the value.
Budget: €800
'use client';
import { useState } from 'react';
import { CrBox, CrSlider } from '@cristal-ui/react';
export default function SliderBasic() {
const [budget, setBudget] = useState(800);
return (
<CrBox display="flex" direction="column" gap="lg" style={{ width: '100%', maxWidth: 360 }}>
<CrSlider label="Volume" name="volume" value={40} />
<CrSlider label="Maximum budget (€)" name="budget" min={0} max={2000} step={50} value={budget} onCrInput={(event) => setBudget(event.detail)} />
<CrSlider label="Brightness (set by the system)" value={70} disabled />
<p>Budget: €{budget.toLocaleString('en-US')}</p>
</CrBox>
);
}In a form
The slider submits its value under its name. onCrInput reports every new value while dragging, onCrChange the final value, when the user releases the thumb.
If the user asked their system to reduce motion, the bubble changes size without transition.
Accessibility
- Under the hood, a native
input type="range": announced as "slider" with its value, set with the arrow keys, Page Up and Page Down, Home and End. labelis required and visible, linked to the slider.- The bubble repeats the value for the eyes only; screen readers read the native slider's value.
- The track stands out from the background with a contrast of at least 3:1; keyboard focus draws an outline around the thumb.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Désactive le curseur. |
label (obligatoire) | string | — | Libellé affiché au-dessus du curseur (obligatoire). |
max | number | 100 | Valeur maximale. |
min | number | 0 | Valeur minimale. |
name | string | — | Nom envoyé avec le formulaire. |
step | number | 1 | Écart entre deux valeurs possibles. |
value | number | 0 | Valeur choisie, ramenée entre min et max. |
Events
| React | event.detail | Description |
|---|---|---|
onCrChange | number | Émis quand l'utilisateur relâche la pastille ou change la valeur au clavier ; detail : la valeur. |
onCrInput | number | Émis pendant le glissement, à chaque nouvelle valeur ; detail : la valeur. |
CSS parts
To style it from outside: cr-slider::part(name) { … }
| Part | Description |
|---|---|
bubble | La bulle qui affiche la valeur. |
control | Le curseur natif (input type="range"). |
label | Le libellé. |