Skip to content
LIBRARYFormsUpdated

Slider ​

m-slider · Numeric selection with bounds and integer or fractional steps.

Web preview
Open example ↗

Usage ​

vue
<m-slider v-model="temperature" :min="16" :max="28" :step="0.5" label="Temperature" />

Values and handlers in this snippet belong to your component. The full example below includes their setup.

API ​

PropTypeDefaultPurpose
modelValue / v-modelnumber0Selected value.
minnumber0Lower bound.
maxnumber100Upper bound.
stepnumber1Step greater than zero.
labelstringrequiredAccessible control name.
disabledbooleanfalsePrevents interaction.
showValuebooleantrueWeb: shows the value in a bubble above the thumb while it is being changed.
formatValue(value: number) => string—Words for the value, used by the bubble and as the accessible value text on every target.
ticksbooleanfalseWeb: marks each step on the track when the range has at most twenty steps.

update:modelValue emits the numeric value snapped to a step. min must be less than max; all values must be finite. External values are clamped and snapped for display without automatically rewriting application state. When the range is not divisible by the step, the final step reaches max. On the Web, arrow keys, Home and End operate the control.

While a Web slider is dragged or moved by keyboard, its thumb grows and a bubble with the current value springs up above it, leaning against the direction of travel and settling when the movement stops. The bubble is decoration: the range input keeps the value text, the focus ring and the hit target, and showValue="false" removes it. NativeScript uses the platform slider, where the bubble and ticks are not drawn; formatValue still provides its accessibility value.

Full example ​

This file also runs in the NativeScript catalog and the Web preview.

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { ref } from 'vue'

const { t } = useCatalogLocale()

withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: 'pt' })
const volume = ref(35)
const temperature = ref(21)
</script>

<template>
  <m-column gap="lg">
    <m-column gap="xs">
      <m-row justify="between">
        <m-text>{{ t('Volume') }}</m-text
        ><m-text tone="primary">{{ t(volume) }}%</m-text>
      </m-row>
      <m-slider
        v-model="volume"
        :step="5"
        ticks
        :formatValue="(value: number) => `${value}%`"
        :label="t('Volume')"
      />
    </m-column>
    <m-column gap="xs">
      <m-row justify="between">
        <m-text>{{ t(lang === 'pt' ? 'Temperatura' : 'Temperature') }}</m-text>
        <m-text tone="primary">{{ t(temperature) }}°</m-text>
      </m-row>
      <m-slider
        v-model="temperature"
        :min="16"
        :max="28"
        :step="0.5"
        :formatValue="(value: number) => `${value}°`"
        :label="t(lang === 'pt' ? 'Temperatura' : 'Temperature')"
      />
    </m-column>
    <m-slider
      :modelValue="60"
      disabled
      :label="t(lang === 'pt' ? 'Controle desabilitado' : 'Disabled control')"
    />
  </m-column>
</template>

In context ​

See the components in a complete vehicle controls screen.

Snapping and controlled value rules.

Accessible names, focus and screen-reader checks.

Desktop ​

Click the desktop track to move the thumb to the nearest step. Drag the thumb or use the arrow keys, Page Up, Page Down, Home and End for further adjustments. Use showValue to show the value in a tooltip. Desktop components.

Components for NativeScript and Web. Starting with Vue.