Skip to content
LIBRARYFormsUpdated

RangeSlider ​

Added in alpha.11

Included in Mavis 0.1.0-alpha.11 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.

Web preview
Open example ↗
vue
<MRangeSlider v-model="budget" :min="0" :max="1000" :step="25" label="Budget" />
PropTypeDefaultDescription
modelValue / v-modelreadonly [number, number][0, 100]Ordered pair; handles cannot cross.
min / max / stepnumber0 / 100 / 1Finite bounds and a positive step; decimals are supported.
lowerLabel / upperLabelstringMinimum / MaximumEndpoint names.
formatValue(number) => string—Display formatting; the model stays numeric.
disabled / readonlybooleanfalsePrevents changes.
showValuebooleantrueWeb: a bubble above the handle being dragged or stepped.
ticksbooleanfalseWeb: marks each step along the track when there are at most twenty.

On Web, two range inputs share the track while keeping independent focus and identity, even when they overlap. Native 48-DIP touch handles respond to pan; labelled MNumberInput fields provide precise editing, keyboard and assistive access. Jolt animates native handle feedback. The numeric track runs left to right. Values snap and clamp; nonfinite values, invalid bounds and reversed pairs are rejected.

On Web, the handle you drag or step with the keyboard grows, and a bubble above it shows the value through formatValue, leaning with quick moves. The chosen band thickens while a handle is held and settles when you let go. The bubble is decoration: each input keeps its own value text. On native, the band thickens the same way and each handle grows under the finger. Forced colors use system colors, and reduced motion keeps the bubble and band without the movement.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
import type { RangeValue } from '@getcortexlabs/mavis-core'
const range = ref<RangeValue>([200, 650])
const nights = ref<RangeValue>([3, 6])
const disabled = ref(false)
const format = (value: number) => `${pt.value ? 'R$' : '$'} ${value}`
const night = (value: number) =>
  pt.value
    ? `${value} ${value === 1 ? 'noite' : 'noites'}`
    : `${value} ${value === 1 ? 'night' : 'nights'}`
</script>

<template>
  <MCard gap="lg" padding="lg">
    <MRow gap="md"
      ><MIcon name="sliders-horizontal" tone="primary" :size="28" /><MText
        variant="heading"
        :text="t('Find your sweet spot', 'Encontre seu intervalo')"
    /></MRow>
    <MText
      :text="t('A weekend away, within reach.', 'Uma viagem de fim de semana que cabe no bolso.')"
      tone="muted"
    />
    <MRangeSlider
      v-model="range"
      :min="0"
      :max="1000"
      :step="25"
      :label="t('Nightly budget', 'Orçamento por noite')"
      :formatValue="format"
      :disabled="disabled"
    />
    <MRangeSlider
      v-model="nights"
      :min="1"
      :max="14"
      ticks
      :label="t('Length of stay', 'Duração da estadia')"
      :lowerLabel="t('Shortest', 'Mais curta')"
      :upperLabel="t('Longest', 'Mais longa')"
      :formatValue="night"
      :disabled="disabled"
    />
    <MSwitch v-model="disabled" :label="t('Lock budget', 'Fixar orçamento')" />
    <MText id="range-value" :text="range.join(' – ')" variant="caption" tone="muted" />
  </MCard>
</template>

Desktop ​

Click the desktop track to move the nearer thumb to that step. Each thumb also responds to dragging and the keyboard, and the ends stay in order. Use showValue to show the value in a tooltip. Desktop components.

Components for NativeScript and Web. Starting with Vue.