Slider
VSlider selects a number or a range with one or two thumbs. Optional number fields allow precise entry.
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(40)
</script>
<template>
<div class="demo">
<VSlider v-model="volume" label="Volume" />
</div>
</template>
<style scoped>
.demo {
inline-size: 20rem;
}
</style>Examples
Range
range uses an ordered pair. Moving one thumb past the other pushes both to the new value.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const budget = ref<[number, number]>([20, 60])
</script>
<template>
<div class="demo">
<VSlider v-model="budget" range label="Budget" />
<p class="value">{{ budget[0] }} to {{ budget[1] }}</p>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-3);
inline-size: 20rem;
}
.value {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>Min and max
min and max set the bounds, including negative values.
Temperature, -10 to 40
19 °C
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const temperature = ref(19)
const rating = ref(3)
</script>
<template>
<div class="demo">
<div class="row">
<p class="caption">Temperature, -10 to 40</p>
<VSlider v-model="temperature" :min="-10" :max="40" label="Temperature" />
<p class="value">{{ temperature }} °C</p>
</div>
<div class="row">
<p class="caption">Rating, 1 to 5</p>
<VSlider v-model="rating" :min="1" :max="5" ticks label="Rating" />
<p class="value">{{ rating }} out of 5</p>
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 20rem;
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.caption,
.value {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>Steps
step sets the increment. ticks marks stops when there are at most 50 steps.
0 to 95 by 10, so the last stop is 90
50
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const quantity = ref(50)
const opacity = ref(0.4)
const odd = ref(50)
</script>
<template>
<div class="demo">
<div class="row">
<p class="caption">step 10, with ticks</p>
<VSlider v-model="quantity" :step="10" ticks label="Quantity" />
</div>
<div class="row">
<p class="caption">step 0.1</p>
<VSlider v-model="opacity" :min="0" :max="1" :step="0.1" ticks label="Opacity" />
<p class="value">{{ opacity }}</p>
</div>
<!-- This step ends at 90, below max 95. More than fifty steps hides the ticks. -->
<div class="row">
<p class="caption">0 to 95 by 10, so the last stop is 90</p>
<VSlider v-model="odd" :max="95" :step="10" ticks label="Coverage" />
<p class="value">{{ odd }}</p>
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 20rem;
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.caption,
.value {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>Text labels
labels names each step and supplies its accessible value text. It also enables ticks.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const size = ref(2)
</script>
<template>
<div class="demo">
<VSlider v-model="size" :min="0" :max="4" :labels="['XS', 'S', 'M', 'L', 'XL']" label="Size" />
</div>
</template>
<style scoped>
.demo {
inline-size: 20rem;
padding-inline: var(--vectis-space-4);
}
</style>Icon labels
Labels can mix strings and objects containing an icon and accessible text.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider, type SliderLabel } from 'vectis-ui'
import { check_circle as checkCircle, error, info, warning } from 'vectis-ui/icons'
const threshold = ref(1)
const labels = [
{ icon: checkCircle, label: 'Silent' },
{ icon: info, label: 'Information' },
{ icon: warning, label: 'Warning' },
{ icon: error, label: 'Error' },
] satisfies SliderLabel[]
</script>
<template>
<div class="demo">
<VSlider v-model="threshold" :min="0" :max="3" :labels="labels" label="Alert threshold" />
<p class="value">{{ labels[threshold]?.label }}</p>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-3);
inline-size: 20rem;
padding-inline: var(--vectis-space-4);
}
.value {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>tooltip displays the value during dragging or keyboard focus.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>
<template>
<div class="demo">
<VSlider v-model="volume" tooltip label="Volume" />
<VSlider v-model="budget" tooltip range label="Budget" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-8);
inline-size: 20rem;
padding-block-start: var(--vectis-space-6);
}
</style>inputs adds VNumberInput fields. Blur or Enter commits the value, bounded and snapped to the step. Invalid entries restore the previous value.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>
<template>
<div class="demo">
<!-- Commit on blur or Enter to avoid clamping partially typed numbers. -->
<VSlider v-model="volume" inputs="ends" label="Volume" />
<VSlider v-model="budget" inputs="ends" range label="Budget" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>ends places fields beside the track; top and bottom place them above or below. On vertical sliders, these become the start and end sides.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const budget = ref<[number, number]>([20, 60])
const volume = ref(40)
const gain = ref<[number, number]>([30, 70])
</script>
<template>
<div class="demo">
<VSlider v-model="budget" inputs="top" range label="Budget" />
<VSlider v-model="volume" inputs="bottom" label="Volume" />
<VSlider v-model="gain" orientation="vertical" inputs="top" range label="Gain" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>formatOptions takes Intl.NumberFormat options and locale a language tag. Both apply to the tooltip, the number fields and the value thumbs announce. min, max and step stay in model units: with style: "percent", 0.25 shows as 25%.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const price = ref<[number, number]>([120, 300])
const discount = ref(0.25)
const euros = { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } as const
const percent = { style: 'percent' } as const
</script>
<template>
<div class="demo">
<VSlider
v-model="price"
range
:max="500"
:step="10"
inputs="ends"
tooltip
label="Price"
:format-options="euros"
/>
<VSlider
v-model="discount"
:max="1"
:step="0.05"
tooltip
label="Discount"
:format-options="percent"
/>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
padding-block-start: var(--vectis-space-6);
}
</style>Field sizes
size adjusts number fields. A size set by VInputGroup takes precedence.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const small = ref(20)
const medium = ref(40)
const large = ref(60)
</script>
<template>
<div class="demo">
<VSlider v-model="small" inputs="ends" size="sm" label="Small" />
<VSlider v-model="medium" inputs="ends" label="Medium" />
<VSlider v-model="large" inputs="ends" size="lg" label="Large" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>Orientation
orientation="vertical" places the lowest value at the bottom.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
const gain = ref(60)
</script>
<template>
<div class="demo">
<VSlider v-model="volume" orientation="vertical" label="Volume" />
<VSlider v-model="budget" orientation="vertical" range tooltip label="Budget" />
<VSlider v-model="gain" class="tall" orientation="vertical" inputs="ends" label="Gain" />
</div>
</template>
<style scoped>
.demo {
display: flex;
align-items: start;
gap: var(--vectis-space-8);
}
.tall {
--vectis-control-size-slider-length: 16rem;
}
</style>Disabled
disabled disables thumbs and number fields.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(30)
const budget = ref<[number, number]>([20, 60])
</script>
<template>
<div class="demo">
<VSlider v-model="volume" disabled label="Volume" />
<VSlider v-model="budget" range :step="10" ticks inputs="ends" disabled label="Budget" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>Read-only
readonly prevents pointer and keyboard changes while preserving focus.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const volume = ref(40)
const budget = ref<[number, number]>([20, 60])
</script>
<template>
<div class="demo">
<VSlider v-model="volume" readonly label="Volume" />
<VSlider v-model="budget" range inputs="ends" readonly label="Budget" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>Invalid
invalid marks thumbs and number fields with aria-invalid and the error style.
<script setup lang="ts">
import { ref } from 'vue'
import { VSlider } from 'vectis-ui'
const quota = ref<[number, number]>([30, 90])
</script>
<template>
<div class="demo">
<VSlider v-model="quota" range inputs="ends" invalid label="Quota" />
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
inline-size: 26rem;
}
</style>label is shown above the slider and names its thumbs; hideLabel hides it visually. Consumer ARIA names take precedence. Native attributes reach the end thumb; in range mode, only that value is submitted.
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, VSlider } from 'vectis-ui'
const volume = ref(40)
const submitted = ref<string | null>(null)
function onSubmit(event: Event) {
const data = new FormData(event.target as HTMLFormElement)
submitted.value = [...data].map(([key, value]) => `${key}=${value}`).join(', ')
}
</script>
<template>
<form class="demo" @submit.prevent="onSubmit">
<VSlider v-model="volume" name="volume" label="Volume" />
<VButton class="submit" type="submit" size="sm" variant="outline" tone="neutral">
Submit
</VButton>
<p class="log">{{ submitted ?? 'Nothing submitted yet' }}</p>
</form>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-3);
inline-size: 20rem;
}
.submit {
justify-self: start;
}
.log {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>API
Props
Events
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
export type SliderLabel = string | { icon: IconSource; label: string }export type SliderValue = number | [number, number]
CSS variables