Bedform UIControls

Slider

Select a numeric value from a range.

Slider

*
*
boolean
*
number
*
number
*
number
*
*
number
*

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.

PropTypeDefault
color"primary" | "secondary" | "destructive" | "dungeons" | "legends" | "realms" | "gold""primary"
orientation"horizontal" | "vertical""horizontal"
variant"default" | "segmented""default"

CSS variables

VariablePurpose
--ore-slider-unitBase size unit
--ore-slider-track-borderTrack border color
--ore-slider-active-range-backgroundActive range background
--ore-slider-active-range-highlightActive range highlight
--ore-slider-track-backgroundInactive track background
--ore-slider-track-highlightInactive track highlight
--ore-slider-thumb-backgroundThumb background
--ore-slider-thumb-highlightThumb highlight
--ore-slider-thumb-shadowThumb shadow
--ore-slider-thumb-borderThumb 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.

On this page