Skip to content

Slider ​

A slider is for a value whose exact number matters less than where it sits in a range. When the number is what the reader is after, use NumberField instead — or both, as a pair.

ts
import { Slider, SliderFill, SliderThumb, SliderTrack } from "ropav";
30
orientation
template
<Slider class="w-64" :default-value="30">
  <Label>Volume</Label>
  <SliderOutput />
  <SliderTrack>
    <SliderFill />
    <SliderThumb />
  </SliderTrack>
</Slider>

One thumb or two ​

Pass a number for one thumb and an array for two. Each SliderThumb then takes the index it controls, and the fill spans between them.

30
20 – 70
slider-basic.vue
vue
<script setup lang="ts">
import { Label, Slider, SliderFill, SliderOutput, SliderThumb, SliderTrack } from "ropav";
</script>

<template>
  <div class="stack">
    <Slider :default-value="30">
      <Label>Volume</Label>
      <SliderOutput />
      <SliderTrack>
        <SliderFill />
        <SliderThumb />
      </SliderTrack>
    </Slider>

    <Slider :default-value="[20, 70]">
      <Label>Price range</Label>
      <SliderOutput />
      <SliderTrack>
        <SliderFill />
        <SliderThumb :index="0" />
        <SliderThumb :index="1" />
      </SliderTrack>
    </Slider>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  width: calc(var(--rp-spacing) * 64);
  flex-direction: column;
  gap: calc(var(--rp-spacing) * 6);
}
</style>

SliderOutput renders the current value, formatted through format-options the same way a number field is. SliderMarks draws the ticks.

Accessibility ​

  • Each thumb is a native range input, so the value and the range are the browser's to announce.
  • Arrow keys move by step, Home and End jump to the ends.
  • Give the slider a Label, or an aria-label when there is no room for one. A two-thumb slider labels each end from the group, so a reader hears which end they are moving.

API ​

Slider

PropTypeDefaultDescription
ariaDescribedbystring—Ids of the elements that describe the slider.
ariaLabelstring—Accessible name, for a slider with no visible label.
ariaLabelledbystring—Ids of the elements that name the slider.
defaultValuenumber | number[]—Value while the slider is uncontrolled.
formatOptionsIntl.NumberFormatOptions—Passed to Intl.NumberFormat to build the value labels.
idstring—Id of the group, and the stem every thumb id grows from.
isDisabledboolean—
maxValuenumber100
minValuenumber0
orientation"horizontal" | "vertical""horizontal"
stepnumber1
valuenumber | number[]—Current value. A number drives one thumb, an array one thumb per entry.

The default slot receives:

Slot propType
isDisabledboolean
orientationSliderOrientation
valuesnumber[]
EventPayload
changenumber | number[]
changeEndnumber | number[]
update:valuenumber | number[]

SliderFill

SliderFill takes nothing but class.

SliderMarks

Slots: default.

SliderOutput

Slots: default.

SliderThumb

PropTypeDefaultDescription
formstring—id of the form to submit with, for a thumb rendered outside it.
indexnumber0Which thumb this is, for a slider with more than one.
isDisabledboolean—Disables this thumb alone.
namestring—Name submitted with the form.

The default slot receives:

Slot propType
isDisabledboolean
isDraggingboolean
isFocusedboolean
isFocusVisibleboolean
isHoveredboolean

SliderTrack

The default slot receives:

Slot propType
isDisabledboolean
orientationSliderOrientation
valuesnumber[]