Search docs

Slider

An input where the user selects a value or range from within a given range.

Follows the WAI-ARIA APG Slider pattern and Multi-Thumb Slider pattern.

import { component$, useStyles$ } from '@builder.io/qwik';
import { Slider } from '@leve-ui/slider';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <Slider.Root defaultValue={[40]} class="slider-default">
      <Slider.Track class="slider-default-track">
        <Slider.Range class="slider-default-range" />
        <Slider.Thumb class="slider-default-thumb" aria-label="Volume" />
      </Slider.Track>
    </Slider.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/slider

Anatomy#

import { Slider } from '@leve-ui/slider'; // or '@leve-ui/core'

<Slider.Root>
  <Slider.Track>
    <Slider.Range />
    <Slider.Thumb />
  </Slider.Track>
  <Slider.HiddenInput />
</Slider.Root>
PartElementDescription
Slider.Root<div>Root container holding state, range bounds, and Field integration.
Slider.Track<div>Interactive track area that jumps the nearest thumb on pointerdown.
Slider.Range<div>Visual range highlight exposing --leve-slider-range-start and --leve-slider-range-size.
Slider.Thumb<span>Draggable, focusable thumb with role="slider" and --leve-slider-thumb-percent.
Slider.HiddenInput<input>Visually hidden number input for native <form> submission and reset.

Examples#

Controlled#

Use bind:value to control the value signal and onValueCommit$ to react when a drag or keyboard change is committed.

Volume50% (committed: 50%)

Range#

Pass multiple values and render multiple Slider.Thumb parts with index. Use minStepsBetweenThumbs to prevent thumbs from crossing or getting too close.

Price range$20 – $80

Vertical#

Set orientation="vertical" for a vertical slider.

Step#

Configure step and largeStep (for PageUp and PageDown), including fractional increments.

Opacity0.5

Disabled#

Set disabled to prevent interaction and remove thumbs from the tab order.

Read-Only#

Set readOnly to keep thumbs focusable while preventing value changes.

With Field#

Inside Field.Root, the first thumb automatically receives aria-labelledby, aria-describedby, disabled, readOnly, required, and invalid.

Adjust the display brightness level.

With Form#

Include Slider.HiddenInput to participate in native <form> submission and reset.

Not submitted

API Reference#

Root#

PropDefaultType
ids–{ control?: string }

Overrides the element IDs of the parts. Inside a Field, the Field's IDs are used instead.

defaultValue[min]number[]

The initial value(s) of the slider (uncontrolled).

bind:value–Signal<number[]>

A signal with the current slider value(s) (controlled).

onValueChange$–QRL<(value: number[]) => void>

Called when the slider value(s) change during dragging or keyboard interaction.

onValueCommit$–QRL<(value: number[]) => void>

Called when the user commits a value change (on pointerup or keyboard interaction).

min0number

The minimum value of the slider.

max100number

The maximum value of the slider.

step1number

The stepping interval for value changes.

largeStepstep * 10number

The stepping interval for PageUp and PageDown keys.

minStepsBetweenThumbs0number

The minimum permitted steps between multiple thumbs.

orientation'horizontal''horizontal' | 'vertical'

The orientation of the slider.

disabledfalseboolean

Disables the slider and prevents interaction. Inside a Field, the Field's disabled also applies.

readOnlyfalseboolean

Makes the slider read-only while keeping thumbs focusable.

requiredfalseboolean

Marks the slider as required for form submission.

invalidfalseboolean

Marks the slider as invalid.

Also accepts all <div> attributes.

Data attributeValue
data-leve-sliderAlways present
data-orientation"horizontal" | "vertical"
data-state"idle" | "dragging"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Track#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-slider-trackAlways present
data-orientation"horizontal" | "vertical"
data-disabledPresent when disabled
data-readonlyPresent when read-only

Range#

No props of its own. Accepts all <div> attributes.

Data attributeValue
data-leve-slider-rangeAlways present
data-orientation"horizontal" | "vertical"
data-disabledPresent when disabled
data-readonlyPresent when read-only
CSS variableValue
--leve-slider-range-startStart offset percentage (0% for single-thumb, first thumb percentage for multi-thumb)
--leve-slider-range-sizeSize percentage from start to end thumb

Thumb#

PropDefaultType
index0number

Zero-based index of this thumb in values.

Also accepts all <span> attributes.

Data attributeValue
data-leve-slider-thumbAlways present
data-indexZero-based thumb index
data-orientation"horizontal" | "vertical"
data-state"idle" | "dragging"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid
CSS variableValue
--leve-slider-thumb-percentThumb position percentage within [min, max]

HiddenInput#

PropDefaultType
index0number

Zero-based index of the thumb value to bind to this input.

form–string

The id of the form element to associate the input with.

Also accepts all <input> attributes.

Data attributeValue
data-leve-slider-hidden-inputAlways present
data-indexZero-based thumb index
data-disabledPresent when disabled

Accessibility#

  • Slider.Thumb renders role="slider" with aria-valuenow, aria-valuemin, aria-valuemax, aria-orientation, and optional aria-disabled, aria-readonly, aria-invalid, aria-labelledby, and aria-describedby.
  • In multi-thumb sliders, aria-valuemin and aria-valuemax dynamically reflect adjacent thumb bounds and minStepsBetweenThumbs.
KeyAction
ArrowRight / ArrowUpIncreases value by step (ArrowRight decreases in RTL)
ArrowLeft / ArrowDownDecreases value by step (ArrowLeft increases in RTL)
PageUpIncreases value by largeStep
PageDownDecreases value by largeStep
HomeMoves thumb to its minimum allowed value
EndMoves thumb to its maximum allowed value