Skip to content

SliderField

SliderField component for selecting numeric values with automatic dual-range support, vertical/horizontal orientation, tooltips, custom marks and complete accessibility according to W3C standards.

Usage examples

Basic SliderField

Simple slider

vue
<script setup>
const volume = ref(50)
</script>

<template>
  <SuSliderField 
    label="Volume"
    :min="0"
    :max="100"
    :showValue="true"
    message="Adjust the volume"
    v-model="volume"
  />
</template>

Dual-range (value range)

Range selection

vue
<script setup>
const priceRange = ref([200, 800])

const formatPrice = (value) => `$${value}`
</script>

<template>
  <SuSliderField 
    label="Price range"
    :min="0"
    :max="1000"
    :step="10"
    :value="priceRange"
    :showValue="true"
    :showLabels="true"
    :formatValue="formatPrice"
    message="Set your budget"
    v-model="priceRange"
  />
</template>

With tooltips

Tooltips on hover

vue
<script setup>
const volume = ref(60)
const range = ref([30, 70])
</script>

<template>
  <!-- Top tooltip -->
  <SuSliderField 
    label="Volume with tooltip"
    :min="0"
    :max="100"
    tooltip="top"
    :showValue="false"
    v-model="volume"
  />
  
  <!-- Bottom tooltip for dual-range -->
  <SuSliderField 
    label="Range with tooltips"
    :min="0"
    :max="100"
    tooltip="bottom"
    :showValue="false"
    v-model="range"
  />
</template>

With custom marks

Marks on slider

vue
<script setup>
const difficulty = ref(60)

const formatDifficulty = (value) => {
  if (value === 0) return 'Easy'
  if (value === 25) return 'Medium'
  if (value === 50) return 'Hard'
  if (value === 75) return 'Expert'
  if (value === 100) return 'Master'
  return value.toString()
}
</script>

<template>
  <SuSliderField 
    label="Difficulty level"
    :min="0"
    :max="100"
    :marks="[0, 25, 50, 75, 100]"
    tooltip="top"
    :formatValue="formatDifficulty"
    v-model="difficulty"
  />
</template>

API

Props

PropTypeDefaultDescription
valuenumber | [number, number]minSlider value (single number or array for dual-range)
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step increment
size'sm' | 'md' | 'lg''md'Slider size
state'default' | 'error' | 'success' | 'warning''default'Visual state
disabledbooleanfalseDisable the slider
readonlybooleanfalseRead-only slider
requiredbooleanfalseRequired field
orientation'horizontal' | 'vertical''horizontal'Slider orientation
tooltip'none' | 'top' | 'bottom''none'Tooltip position on hover
marksnumber[][]Marks to display on slider
showValuebooleantrueShow current value
showTicksbooleanfalseShow tick marks
showLabelsbooleanfalseShow min/max labels
formatValue(value: number) => stringundefinedValue formatting function
dir'ltr' | 'rtl' | 'auto''auto'Text direction
labelstringundefinedSlider label
messagestringundefinedDisplayed message

Events

EventTypeDescription
@update:modelValue(value: number | [number, number]) => voidEmitted when value changes (v-model)
@change(value: number | [number, number]) => voidEmitted on change
@input(value: number | [number, number]) => voidEmitted during dragging
@focus(event: FocusEvent) => voidEmitted on focus
@blur(event: FocusEvent) => voidEmitted on blur
@keydown(event: KeyboardEvent) => voidEmitted on key press

Slots

SlotDescription
beforeContent displayed before the slider
afterContent displayed after the slider

Automatic dual-range detection

The component automatically detects if it should work in dual-range mode by checking if the value is an array:

vue
<!-- Single mode -->
<SuSliderField :value="50" />

<!-- Dual-range mode (automatically detected) -->
<SuSliderField :value="[20, 80]" />

Tooltips

Tooltips display the formatted value on hover or focus of the thumbs:

🎯 Available positions

  • tooltip="none" : No tooltip (default)
  • tooltip="top" : Tooltip above the thumb
  • tooltip="bottom" : Tooltip below the thumb
vue
<!-- Top tooltip -->
<SuSliderField tooltip="top" :value="50" />

<!-- Bottom tooltip -->
<SuSliderField tooltip="bottom" :value="[20, 80]" />

<!-- No tooltip, static display -->
<SuSliderField tooltip="none" :showValue="true" :value="50" />

Custom marks

Marks allow displaying specific values on the slider:

📍 Mark features

  • Automatic positioning : Percentage position calculation
  • Smart filtering : Only marks within min/max range are displayed
  • Formatting : Uses formatValue function if provided
  • RTL support : Position adapted to direction
vue
<script setup>
const temperature = ref(22)

const formatTemp = (value) => `${value}°C`
</script>

<template>
  <SuSliderField 
    label="Temperature"
    :min="0"
    :max="40"
    :marks="[0, 10, 18, 24, 30, 40]"
    :formatValue="formatTemp"
    tooltip="top"
    v-model="temperature"
  />
</template>

Before and after slots

Slots allow adding custom content around the slider:

🎨 Use cases

  • Icons : Visual indicators (🔇 🔊)
  • Labels : Text descriptions
  • Buttons : Quick actions (reset, presets)
  • Information : Additional context
vue
<template>
  <SuSliderField 
    label="Brightness"
    :min="0"
    :max="100"
    v-model="brightness"
  >
    <template #before>
      <div class="slider-controls">
        <span>🌙</span>
        <span>Dark</span>
      </div>
    </template>
    <template #after>
      <div class="slider-controls">
        <span>Bright</span>
        <span>☀️</span>
      </div>
    </template>
  </SuSlider>
</template>

RTL Support

The component automatically handles right-to-left languages:

🌐 RTL features

  • Automatic inversion : Percentages are inverted
  • Adapted calculation : Thumb position adjusted
  • Marks and ticks : Correct positioning
  • Keyboard navigation : Arrows adapted to direction
vue
<!-- RTL support -->
<SuSliderField 
  label="مستوى الصوت"
  dir="rtl"
  :min="0"
  :max="100"
  :value="70"
  tooltip="top"
/>

<!-- Auto-detection -->
<SuSliderField 
  label="Volume"
  dir="auto"
  :value="50"
/>

Accessibility

The Slider component follows WCAG 2.1 AA standards and W3C best practices:

✅ Accessibility features

  • ARIA role : role="slider" with aria-valuemin, aria-valuemax, aria-valuenow
  • Keyboard navigation : Support for arrow keys, Page Up/Down, Home/End
  • ARIA orientation : aria-orientation for screen readers
  • Voice announcements : Messages for screen readers on value changes
  • Associated labels : Each slider has a properly associated label
  • State messages : Messages with aria-live for screen readers
  • Color contrast : WCAG AA compliant contrast ratios (4.5:1 minimum)
  • Visible focus : Clear and contrasted focus indicators
  • Minimum sizes : 44px minimum thumbs for touch accessibility
  • Dark mode : Automatically adapted contrast
  • High contrast : Support for prefers-contrast: high
  • Reduced motion : Respects prefers-reduced-motion

Keyboard navigation

KeyAction
TabNavigate to/from slider
ArrowsAdjust value by step
Page UpIncrease by 10% of range
Page DownDecrease by 10% of range
HomeGo to minimum value
EndGo to maximum value

Publié sous licence MIT.