Vitral 0.2
Form

Slider

Pick a value, or a range, by dragging along a track or with the keyboard.

Import

main.ts
import { Slider } from '@vitral/vue';

Basic

Volume
Value: 40
Opacity
Value: 0.6
<script setup lang="ts">import { Slider, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const volume = ref(40);const opacity = ref(0.6);</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" class="slider-demo">            <span id="sl-volume">Volume</span>            <Slider v-model="volume" aria-labelledby="sl-volume" />            <small style="color: var(--vt-text-muted-color)">Value: {{ volume }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" class="slider-demo">            <span id="sl-opacity">Opacity</span>            <Slider v-model="opacity" :min="0" :max="1" :step="0.05" aria-labelledby="sl-opacity" :format-value="(v: number) => `${Math.round(v * 100)}%`" />            <small style="color: var(--vt-text-muted-color)">Value: {{ opacity }}</small>        </StackPanel>    </StackPanel></template> <style scoped>.slider-demo {    width: 20rem;}</style>

Range

v-model is [start, end]. One name covers both thumbs, which are told apart as minimum and maximum.

Price
R$ 200 – R$ 750
<script setup lang="ts">import { Slider, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const price = ref([200, 750]);</script> <template>    <StackPanel spacing="0.375rem" class="slider-demo">        <span id="sl-price">Price</span>        <Slider v-model="price" range :min="0" :max="1000" :step="10" aria-labelledby="sl-price" :format-value="(v: number) => `R$ ${v}`" />        <small style="color: var(--vt-text-muted-color)">R$ {{ price[0] }} – R$ {{ price[1] }}</small>    </StackPanel></template> <style scoped>.slider-demo {    width: 20rem;}</style>

Vertical

The minimum is at the bottom; Up and Right both increase.

Bass 30 · Treble 70 · 21 °C
<script setup lang="ts">import { Slider } from '@vitral/vue';import { ref } from 'vue'; const bass = ref(30);const treble = ref(70);const temperature = ref(21);</script> <template>    <Slider v-model="bass" orientation="vertical" aria-label="Bass" />    <Slider v-model="treble" orientation="vertical" aria-label="Treble" />    <Slider v-model="temperature" orientation="vertical" :min="16" :max="30" :step="0.5" aria-label="Temperature" :format-value="(v: number) => `${v} °C`" />    <small style="color: var(--vt-text-muted-color)">Bass {{ bass }} · Treble {{ treble }} · {{ temperature }} °C</small></template>

Disabled

<script setup lang="ts">import { Slider, StackPanel } from '@vitral/vue';</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" class="slider-demo">            <Slider :model-value="60" disabled aria-label="Disabled" />        </StackPanel>        <StackPanel spacing="0.375rem" class="slider-demo">            <Slider :model-value="[25, 75]" range disabled :aria-label="['Disabled start', 'Disabled end']" />        </StackPanel>    </StackPanel></template> <style scoped>.slider-demo {    width: 20rem;}</style>

API

Read from packages/vue/src/components/Slider/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
minnumberDefaults to 0.
maxnumberDefaults to 100.
stepnumberDistance between neighbouring values; defaults to 1. 0 lets the thumb stop anywhere.
rangebooleanTwo thumbs: v-model is `[start, end]`, and the thumbs never cross.
orientation'horizontal' | 'vertical'A vertical slider has its minimum at the bottom.
disabledboolean—
formatValue(value: number) => stringText a screen reader announces for a value (`aria-valuetext`): "20 °C" rather than "20".
ariaLabelstring | string[]The thumb's accessible name. For a range, one string names both thumbs together with the locale's "minimum"/"maximum"; an array names each.
ariaLabelledbystring | string[]Id(s) of the element(s) naming the thumbs; an array names each thumb of a range.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
changevalue: SliderValueThe value was committed: after a key press, or when a drag ends having moved it.
slideendevent: SliderSlideEndEventA pointer interaction ended.