Skip to content

Slider ​

17:06

Description ​

Drags to select a value within start–end, two-way bound via v-model, with step controlling the increment and min / max further restricting the draggable range. Optionally shows the current value (show-value, positioned by value-position) and the two edge values (show-edge-value); the thumb provides a default slot for custom content.

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported
WeChat Mini Program✅ Supported

Examples ​

Basic Usage ​

Bind value via v-model; drag the thumb or tap the bar to change.

View source
vue
<template>
    <ux-slider v-model="value" />
</template>

<script setup lang="uts">
const value = ref<number>(30);
</script>

Custom Range ​

Set range via start/end, step via step; here -50 to 50 with step 5.

View source
vue
<template>
    <ux-slider v-model="value" :start="-50" :end="50" :step="5" />
</template>

<script setup lang="uts">
const value = ref<number>(0);
</script>

Show Value ​

When show-value=true, display the current value above the thumb.

View source
vue
<template>
    <ux-slider v-model="value" :show-value="true" />
</template>

<script setup lang="uts">
const value = ref<number>(50);
</script>

Value & Edge Positions ​

value-position moves the current value below the track; show-edge-value=true prints the start/end values at both ends. These labels are out of flow, so the component reserves the space for them and they never overlap neighbouring elements.

View source
vue
<template>
    <ux-slider v-model="value1" :show-value="true" value-position="bottom" />
    <ux-slider v-model="value2" custom-class="slider-gap" :show-value="true" :show-edge-value="true" edge-value-position="top" />
</template>

<script setup lang="uts">
const value1 = ref<number>(35);
const value2 = ref<number>(70);
</script>

<style lang="scss">
.slider-gap {
    margin-top: 20px;
}
</style>

Custom Color ​

Customize progress bar colors via active-color and inactive-color.

View source
vue
<template>
    <ux-slider v-model="value" active-color="#fa3534" inactive-color="#e4e7ed" />
</template>

<script setup lang="uts">
const value = ref<number>(40);
</script>

Disabled ​

When disabled=true, the slider cannot be dragged.

View source
vue
<template>
    <ux-slider v-model="value" :disabled="true" />
</template>

<script setup lang="uts">
const value = ref<number>(60);
</script>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom root element styleUTSJSONObject--
customClassCustom root element style classstring''-
modelValueCurrent value (default 0)number | string0-
startStart value of the overall range (default 0)number | string0-
endEnd value of the overall range (default 50)number | string100-
minMinimum draggable value (default 0)number | string0-
maxMaximum draggable value (default 50)number | string100-
stepStep size (default 1)number | string1-
blockWidthThumb width; height equals width, in px (default 15)number | string15-
heightTrack height in px (default 3)number | string3-
activeColorColor of the active (filled) part of the trackstring''-
inactiveColorBackground color of the trackstring''-
blockColorThumb colorstring''-
blockStyleCustom thumb styleUTSJSONObject--
disabledWhether the slider is disabled (default false)booleanfalse-
showValueWhether to show the current value (default false)booleanfalse-
valuePositionPosition of the value: top – above, bottom – below (default top)string'top'-
showEdgeValueWhether to show the start and end values (default false)booleanfalse-
edgeValuePositionPosition of the start/end values (default top)string'top'-
validateStateWhether in a validation error state (linked from the parent form-item, default false)booleanfalse-

Events ​

EventDescriptionParamsVersion
startFires when dragging starts--
movingFires continuously while dragging--
endFires when dragging ends--

Slots ​

SlotDescriptionVersion
defaultCustom thumb content (defaults to a white round thumb)-

Notes ​

  • The effective drag range is decided by min / max together with start / end: min / max are clamped inside start / end.
  • The final value is rounded to align with step (Math.round(v / step) * step); a non-positive step is treated as 1.
  • The show-value / show-edge-value labels are absolutely positioned and take no in-flow height, so the component reserves space above/below the root (26px each) to avoid overlapping neighbouring elements.
  • While dragging, update:modelValue and moving are emitted continuously; start fires when dragging begins and end when it finishes.
  • The thumb is square (both width and height use block-width) and supports a default slot for custom content.
  • The component can inject the ux-form-item context and triggers its validation after a drag ends or the track is tapped; validate-state adds a red border on the track.