Skip to content

Slider ​

Picks an approximate value in a small range by dragging, such as a discount or a maximum price.

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const korting = ref(10)
</script>

<template>
  <FsSlider v-model="korting" label="Korting (%)" :max="30" :step="5" class="w-full max-w-md" />
</template>

Usage ​

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const korting = ref(10)
</script>

<template>
  <FsSlider v-model="korting" label="Korting (%)" :max="30" />
</template>

When the exact number matters, use Number input. A slider always has a value within its range, so it takes no invalid or required.

Examples ​

Formatted value ​

formatOptions writes the value, and the limits, as currency, a percentage or a plain number, in the app's language. A percentage is given in points: 25 is "25%".

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const prijs = ref(2000)
</script>

<template>
  <FsSlider
    v-model="prijs"
    label="Maximale prijs"
    :max="5000"
    :step="100"
    :format-options="{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }"
    class="w-full max-w-md"
  />
</template>

Showing the limits ​

showLimits writes the lowest and the highest value under the ends of the track.

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const prijs = ref(2000)
</script>

<template>
  <FsSlider
    v-model="prijs"
    label="Maximale prijs"
    :max="5000"
    :step="100"
    :format-options="{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }"
    show-limits
    class="w-full max-w-md"
  />
</template>

Custom value text ​

Where a format cannot say it, valueText writes the value instead, both shown and read aloud.

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const dagen = ref(14)
</script>

<template>
  <FsSlider
    v-model="dagen"
    label="Betaaltermijn"
    :min="7"
    :max="60"
    :value-text="(value) => `${value} dagen`"
    show-limits
    class="w-full max-w-md"
  />
</template>

Disabled and read-only ​

A disabled slider cannot be focused or submitted. A read-only slider keeps its value fixed but stays focusable and submitted.

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const korting = ref(10)
</script>

<template>
  <div class="flex w-full max-w-md flex-col gap-6">
    <FsSlider v-model="korting" label="Korting (%)" :max="30" disabled />
    <FsSlider v-model="korting" label="Korting (%), vastgesteld in het contract" :max="30" readonly />
  </div>
</template>

Without a visible label ​

Name a slider that has no label with aria-label or aria-labelledby. The value then stands beside the track.

vue
<script setup lang="ts">
import { FsSlider } from '@fivespark/ui'
import { ref } from 'vue'

const korting = ref(10)
</script>

<template>
  <FsSlider v-model="korting" aria-label="Korting in procenten" :max="30" class="w-full max-w-md" />
</template>

Keyboard ​

KeyDoes
←, ↓Lowers the value by one step
→, ↑Raises the value by one step
Page Down, Page UpMoves the value by a tenth of the range
Home, EndGoes to the lowest or the highest value

API Reference ​

FsSlider ​

PropTypeDefaultDescription
labelstringThe visible name, with its unit when the value shows none. Without one, name it with `aria-labelledby` or `aria-label`.
minnumber0The lowest value.
maxnumber100Below `min`, it is `min`.
stepnumber1Divides the range: 0 to 100 by 10, not by 30.
formatOptionsIntl.NumberFormatOptionsHow the value, the limits and the value read out are written, in the component's language: `{ style: 'currency', currency: 'EUR' }`. A percentage is in points: 25 is "25%"; with a step below 1, give it `maximumFractionDigits`.
valueText((value: number) => string)Replaces the formatted value, shown and read, where a format cannot say it: "3 dagen". The limits too.
showLimitsbooleanfalseShows the limits under the ends.
idstringWithout a field. In a field, the slider takes the field's.
disabledbooleanUnavailable for now. In a field, the slider takes the field's.
readonlybooleanFocusable and submitted, its value fixed. Say why in the field's description.
readonlyTextstringReplaces the hidden "alleen lezen" or "read-only".
modelValuenumberThe value. A value off the range or between steps is shown where the browser puts it.
EventPayloadDescription
update:modelValue[value: number | undefined]Sent with the new `modelValue`, for `v-model`.