Slider
Single or range values, frame-coalesced touch updates and a committed change event on release.
Import
With uni-app easycom, use hui-slider。 Standalone Vue imports @nscode/handy-uni/web HuiSlider or installs the preview plugin.
Examples
Interaction and event results
Interact with the control. The latest event and its full payload are shown below. Popup selectors commit only after confirmation; cancellation keeps the previous value.
vue
<script setup lang="ts">
import { ref } from 'vue'
import type { SliderValue } from '@nscode/handy-uni'
const result = ref('')
const value = ref<SliderValue>([20, 60])
function event0(arg0: unknown) {
result.value = 'update:modelValue' + ': ' + JSON.stringify([arg0])
}
function event1(arg0: unknown) {
result.value = 'change' + ': ' + JSON.stringify([arg0])
}
function event2(arg0: unknown) {
result.value = 'drag-start' + ': ' + JSON.stringify([arg0])
}
function event3(arg0: unknown) {
result.value = 'drag-end' + ': ' + JSON.stringify([arg0])
}
</script>
<template>
<view>
<hui-slider
v-model="value"
range
:step="5"
show-stops
:marks="{ 0: '0', 50: '50', 100: '100' }"
show-value
@update:model-value="event0"
@change="event1"
@drag-start="event2"
@drag-end="event3"
></hui-slider>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | SliderValue | undefined | undefined | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | SliderValue | undefined | — | Initial uncontrolled value. |
min | number | undefined | 0 | Lower value bound, or minimum count for multiple selection. |
max | number | undefined | 100 | Upper bound, star count for Rate, or maximum multiple-selection count. |
step | number | undefined | 1 | Positive step; invalid or nonpositive values use one. |
range | boolean | undefined | false | Use two thumbs for a range value. |
marks | Record<number, string> | undefined | — | Tick-label map, cached by value signature. |
show-stops | boolean | undefined | false | Show step stops, omitted above fifty segments. |
vertical | boolean | undefined | false | Vertical slider; provide a height. |
height | readonly [NumberConstructor, StringConstructor] | undefined | — | Height; numeric values use pixels. |
disabled | boolean | undefined | false | Disable user interaction, including inherited form state. |
readonly | boolean | undefined | undefined | Readonly; inherit form context when omitted. |
show-value | boolean | "drag" | undefined | — | true always displays values; drag displays them during dragging. |
format-value | ((value: number) => string) | undefined | — | Format visible and accessible values. |
size | ComponentSize | undefined | — | small, default or large size. |
custom-class | string | undefined | '' | Additional root classes. |
custom-style | string | CSSProperties | undefined | — | Additional root styles. |
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: SliderValue) | Requests a controlled value update. |
change | (value: SliderValue) | Reports change with the arguments shown in the example. |
drag-start | (info: { thumb: 0 | 1; }) | Reports drag-start with the arguments shown in the example. |
drag-end | (info: { thumb: 0 | 1; }) | Reports drag-end with the arguments shown in the example. |
Slots
| Slot | Description |
|---|---|
thumb | Thumb scope: {value,index,dragging}. |
mark | Mark scope: {value,label}. |
Methods
| Method | Signature |
|---|
Types
SliderProps、SliderEmits。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | All targets share controlled values, steps and range calculations. Position is updated using platform measurements and touch events. |
| Device checks pending | Check horizontal and vertical dragging, range boundaries and page scrolling on devices; also check arrow keys in ordinary Vue. |
See examples/uni-demo/smoke/Slider.md for the checklist. Unit tests do not replace device acceptance.