Slider
Select a numeric value from a range.
Slider
Usage
import { Slider } from "@bedform/ui/slider";
import { useState } from "react";
export function RenderDistanceSlider() {
const [value, setValue] = useState(12);
return (
<Slider
aria-label="Render distance"
name="distance"
min={2}
max={32}
step={1}
value={value}
onInput={(event) => {
setValue(event.currentTarget.valueAsNumber);
}}
/>
);
}Variants
<Slider defaultValue={40} aria-label="Volume" />
<Slider variant="segmented" defaultValue={40} aria-label="Volume" />Colors
<Slider color="primary" defaultValue={40} aria-label="Primary volume" />
<Slider color="secondary" defaultValue={40} aria-label="Secondary volume" />
<Slider color="destructive" defaultValue={40} aria-label="Destructive volume" />
<Slider color="dungeons" defaultValue={40} aria-label="Dungeons volume" />
<Slider color="legends" defaultValue={40} aria-label="Legends volume" />
<Slider color="realms" defaultValue={40} aria-label="Realms volume" />
<Slider color="gold" defaultValue={40} aria-label="Gold volume" />Orientation
orientation also sets aria-orientation.
<Slider orientation="horizontal" defaultValue={40} aria-label="Horizontal value" />
<Slider orientation="vertical" defaultValue={40} aria-label="Vertical value" />Events
The native range input dispatches input while its value changes and change when the interaction is committed, so use onInput to follow the thumb and read event.currentTarget.valueAsNumber for a numeric value. name, form submission, reset, disabled fieldsets, and keyboard behavior use the browser's native implementation.
API
Slider renders a native range input and accepts every input attribute except type, such as min, max, step, value, defaultValue, name and disabled. Its ref points to the input.
| Prop | Type | Default |
|---|---|---|
color | "primary" | "secondary" | "destructive" | "dungeons" | "legends" | "realms" | "gold" | "primary" |
orientation | "horizontal" | "vertical" | "horizontal" |
variant | "default" | "segmented" | "default" |
CSS variables
| Variable | Purpose |
|---|---|
--ore-slider-unit | Base size unit |
--ore-slider-track-border | Track border color |
--ore-slider-active-range-background | Active range background |
--ore-slider-active-range-highlight | Active range highlight |
--ore-slider-track-background | Inactive track background |
--ore-slider-track-highlight | Inactive track highlight |
--ore-slider-thumb-background | Thumb background |
--ore-slider-thumb-highlight | Thumb highlight |
--ore-slider-thumb-shadow | Thumb shadow |
--ore-slider-thumb-border | Thumb border color |
Accessibility
Add an accessible name with a visible <label> or aria-label. Slider preserves the native range input's pointer, touch, keyboard, form, disabled, and reset behavior. orientation="vertical" sets aria-orientation="vertical" for you.