Slider
Alignment target:@astryxdesign/core v0.7.1 · Slider
Usage #
Use Slider to choose a number or numeric range.
<script setup lang="ts">
import { Slider } from '@astryx-vue/core/Slider'
import { shallowRef } from 'vue'
const volume = shallowRef(50)
const budget = shallowRef<[number, number]>([20, 80])
</script>
<template>
<Slider v-model="volume" label="Volume" />
<Slider v-model="budget" label="Budget" value-display="text" />
</template>Import the theme once in the application entry:
import '@astryx-vue/themes/neutral.css'Anatomy
| Element | Description |
|---|---|
| Label | Text identifying the numeric setting controlled by the slider. |
| Description | Helper text between the label and the slider control. |
| Slider | Control row containing the track, thumb or thumbs, and optional text value. |
| Interactive control | Pointer and keyboard interaction surface containing the rail, fill, marks, and thumbs. |
| Track | Background rail representing the available numeric range. |
| Filled range | Accent segment from the minimum to a single value, or between two range values. |
| Tick mark | Position marker supplied through the marks collection. |
| Mark label | Optional text displayed beside a tick mark. |
| Thumb | Draggable value indicator; range mode renders a minimum and maximum thumb. |
| Value display | Formatted current value shown beside the slider when valueDisplay is text. |
| Value tooltip | Formatted current value shown in a tooltip when valueDisplay is tooltip. |
| Status message | Error, warning, or success message below the slider. |
Best practices #
| Guidance | Practices |
|---|---|
| Do | Always provide a label, even if visually hidden, so the slider is accessible to screen readers. |
| Do | Format values with meaningful units like "$50" or "75%" instead of raw numbers. |
| Don't | Use for precise numeric entry; pair with a text input or use NumberInput instead. |
| Don't | Set a step size so large that only a few positions are possible; use SegmentedControl or radio buttons instead. |
| Don't | Wrap a disabled slider in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead. |
Examples #
Slider — Formatted value
Temperature in Fahrenheit, shown beside the slider.
Slider — Range
A price range with a lower and an upper thumb.
Slider — Marks
Volume with tick labels at 0, 25, 50, 75, and 100.
Slider — Validation states
Error, warning, and success on CPU, memory, and disk.
Keyboard controls #
The slider is fully operable with the keyboard, so users never have to drag. Once a thumb has focus, these keys change its value:
- Tab moves focus to each thumb in turn.
- Left / Right move one step in the horizontal direction; the direction is reversed in right-to-left layouts.
- Up / Down increase or decrease the value by one step.
- PageUp / PageDown increase or decrease the value by ten steps.
- Home / End move to the allowed minimum or maximum.
- Escape closes the value tooltip or the disabled reason tooltip.
In range mode each thumb has its own name, taken from minLabel and maxLabel, so assistive technology can tell which bound is being adjusted. Each thumb's ARIA bounds also update when its sibling changes, so the range that is announced always matches the values the thumb can actually take.
Usage guidance #
A slider suits choosing a value along a continuous range, not entering an exact number. Keep the following in mind:
- Provide a numeric input when exact entry matters.
isRequiredonly provides a required description, so assistive technology knows the field is required.- Validate accepted values in application code.