Slider
Labelled native range input.
import { Slider } from '@elirobinson/react/components/atoms/Slider';Styles: @elirobinson/react/styles/atoms/Slider.css — already included when you import @elirobinson/react/styles.css.
Show code
import { Slider } from '@elirobinson/react/components/atoms/Slider';
export default function Basic() {
return <Slider label="Volume" min={0} max={100} defaultValue={50} />;
}When to use it
Use Slider for a value picked from a continuous or stepped numeric range, where the
gesture matters more than the exact typed number — volume, brightness, a price range.
Use Input type="number" instead when typed precision is the point (dollar amounts,
exact ages).
Controlled
Slider doesn't render the current value anywhere — show it yourself off the same
state.
45 minutes per session.
Show code
import { useState } from 'react';
import { Slider } from '@elirobinson/react/components/atoms/Slider';
export default function Controlled() {
const [minutes, setMinutes] = useState(45);
return (
<div className="demo-col">
<Slider
label="Session length"
min={15}
max={90}
step={15}
value={minutes}
onChange={(event) => setMinutes(Number(event.target.value))}
/>
<p>{minutes} minutes per session.</p>
</div>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | — |
Also accepts all Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> props.
Accessibility
- Renders a native
<input type="range">, which carries the implicitsliderrole and full keyboard support from the browser — arrow keys adjust bystep,Home/Endjump to the min/max. Nothing here reimplements it. - The label is a real
<label htmlFor>pointed at the input's id, auto-generated withuseIdwhen you don't pass one. - No value bubble or tooltip appears while dragging — if readers need to see the number, render it next to the slider yourself.
- The ref forwards to the underlying
<input>.
Do
- Always pass min, max, and a sensible step — the native range default (0–100, step 1) is rarely what you actually want.
- Show the live value near the slider yourself when the exact number matters — the component doesn’t render one.
- Use defaultValue for uncontrolled, or value + onChange for controlled — same native contract as any range input.
Don't
- Expect a tooltip or value bubble to appear automatically while dragging — build it yourself off the same state.
- Use Slider for a value that needs typed precision — Input type="number" is more honest there.
- Forget the label — it’s required, and it’s the only accessible name the range input gets.