vael-ui v0.5.7

Forms & inputs

Layout

Slider

A track with one thumb for a value, or two for a range. Use it to pick a number by dragging.

Validating a form? vael-form wires this up with a schema

Install

import { Slider } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Slider } from 'vael-ui'

const value = ref(0)
</script>

<template>
  <Slider aria-label="Volume" v-model="value" />
</template>

Props

NameTypeDefaultDescription
minnumber0Lowest allowed value.
maxnumber100Highest allowed value.
stepnumber1Increment the value snaps to; arrow keys move one step, Page Up/Down ten.
orientation'horizontal' | 'vertical''horizontal'Lays the track out horizontally or vertically.
disabledbooleanfalseDisables the slider and blocks interaction.
invalidbooleanfalseShows the invalid state. A surrounding Field in error sets it too.
namestringNative name for form submission, via one hidden input per thumb.
valueText((value: number) => string)Drives aria-valuetext, e.g. (v) => \$${v}\`` for a currency slider.
uiPartial<Record<'root' | 'track' | 'fill' | 'thumb', UiPartValue>>Class and style overrides for each part.
motionSliderMotionHow it moves: its appearance ({ initial: { thumb: { opacity: 0, scale: 0.6 } } }) and its states ({ states: { focus: { thumb: { scale: '1.15' } } } }). { when: 'visible' } holds its appearance until it scrolls into view. false turns its own animation off.
modelValuenumber | [number, number]0Current value. Bind a [start, end] tuple for a two-thumb range.

Events

NameTypeDescription
update:modelValue(value: number | [number, number])Fires when modelValue changes (v-model).
change(value: number | [number, number])Fires with the final value when you release a thumb or press a key, like a native range input's change. v-model updates on every move.

Slots

NameTypeDescription
thumb{ value: number; index: number; percent: number; active: boolean; dragging: boolean; }Content inside each thumb, such as a value bubble or an icon. The thumb keeps its role and keyboard handling.
track{ values: number[]; percents: number[]; dragging: boolean; }Content inside the track, under the thumbs, such as ticks or an inline label.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
trackElHTMLElement | nullTrack element.
fillElHTMLElement | nullFilled portion of the track.
thumbElsHTMLElement[] | nullThumb elements, one per value (two in range mode).
draggingbooleantrue while a thumb is being dragged.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Slider's motion: values or hooks for its parts (SliderPart), its states (disabled, focus), how its value changes. false turns it off.

<Slider
  :motion="{ states: { disabled: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitroottrackfillthumbSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesdisabledfocusSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
spring{ damping, response }Times how its value moves when it changes, from the steppers, the keyboard or your code.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Slider pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowRightArrowUpIncreases the value by one step.
ArrowLeftArrowDownDecreases the value by one step.
PageUpIncreases the value by ten steps.
PageDownDecreases the value by ten steps.
HomeSets the value to min.
EndSets the value to max.
  • Each thumb has role="slider" with aria-valuenow, aria-valuemin and aria-valuemax, plus aria-orientation="vertical" when vertical and aria-invalid when invalid. valueText sets aria-valuetext, such as a price with its currency.
  • In a range, the thumbs are named “Minimum” and “Maximum” after the label. Each thumb’s aria-valuemin or aria-valuemax stops at the other thumb.
  • Inside a Field, the label names the thumbs. Without one, pass aria-label: it moves from the wrapper to the thumbs, as aria-describedby does.
  • Pressing the track moves the nearest thumb there and focuses it. Right to left, ArrowLeft and ArrowRight swap; a vertical slider keeps its keys.