Skip to content

Slider

Rules

Basic Example

js
const rule = {
    type:"slider",
    field:"slider",
    title:"Slider",
    value:[0,52],
    props:{
        min: 0,
        max: 100,
        range: true,
    }
}

Props Configuration Examples

Single Value Slider

js
const rule = {
    type:"slider",
    field:"volume",
    title:"Volume",
    value:50,
    props:{
        min: 0,
        max: 100,
    }
}

Range Slider

js
const rule = {
    type:"slider",
    field:"priceRange",
    title:"Price Range",
    value:[0,100],
    props:{
        min: 0,
        max: 1000,
        range: true,
    }
}

Show Marks

js
const rule = {
    type:"slider",
    field:"discount",
    title:"Discount Rate",
    value:0.5,
    props:{
        min: 0,
        max: 1,
        step: 0.1,
        dots: true,
        marks: {
            0: '0%',
            0.5: '50%',
            1: '100%'
        },
    }
}

Vertical Slider

js
const rule = {
    type:"slider",
    field:"height",
    title:"Height",
    value:50,
    props:{
        vertical: true,
        min: 0,
        max: 100,
    }
}

Events Examples

Listen to Slider Changes

js
const rule = {
    type:"slider",
    field:"volume",
    title:"Volume",
    value:50,
    props:{
        min: 0,
        max: 100,
    },
    on: {
        change: (value) => {
            console.log('Value changed (dragging):', value);
        },
        afterChange: (value) => {
            console.log('Value changed (drag ended):', value);
        },
    },
}

Update Display After Range Changes

js
const rule = [
    {
        type:"slider",
        field:"priceRange",
        title:"Price Range",
        value:[0,100],
        props:{
            min: 0,
            max: 1000,
            range: true,
        },
        inject: true,
        on: {
            afterChange: ($inject, value) => {
                // Update the price range display
                const [min, max] = value;
                $inject.api.setValue('priceRangeText', `¥${min} - ¥${max}`);
            },
        },
    },
    {
        type:"input",
        field:"priceRangeText",
        title:"Price Range",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: Ant-design-vue_Slider

value :Number | Array

Props

ParameterDescriptionTypeDefault
autofocusAuto focusbooleanfalse
disabledWhen value is true, slider is disabledbooleanfalse
dotsWhether can only drag to marksbooleanfalse
includedEffective when marks is not empty object, when value is true means inclusive relationship, false means parallelbooleantrue
markCustom markv-slot:mark{ point: number, label: any }
marksMark marks, key type must be number and value must be in closed interval [min, max], each label can set style separatelyobject{ number : string|VNode } or { number: { style: object, label: string|VNode } } or { number: () => VNode }
maxMaximum valuenumber100
minMinimum valuenumber0
rangeDual slider modebooleanfalse
reverseReverse coordinate axisbooleanfalse
stepStep value, must be greater than 0 and divisible by (max - min). When marks is not empty object, can set step to null, at this time Slider's selectable values are only the parts marked by marks.number|null1
verticalWhen value is true, Slider is vertical directionBooleanfalse
tipFormatterSlider will pass current value to tipFormatter, and display return value of tipFormatter in Tooltip, if null, hide Tooltip.Function|nullIDENTITY
tooltipPlacementSet Tooltip display position. Reference Tooltip.string
tooltipOpenWhen value is true, Tooltip will always display; otherwise always not display, even when dragging and hovering.Boolean
getTooltipPopupContainerTooltip rendering parent node, default renders to body.Function() => document.body

Events

Event NameDescriptionCallback Parameters
changeWhen Slider's value changes, change event will be triggered, and changed value will be passed as parameter.Function(value)
afterChangeConsistent with mouseup trigger timing, current value is passed as parameter.Function(value)

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.