Skip to content

Slider 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,
        showInput: true,
    }
}

Range Slider

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

Show Stops

js
const rule = {
    type:"slider",
    field:"discount",
    title:"Discount Rate",
    value:0.5,
    props:{
        min: 0,
        max: 1,
        step: 0.1,
        showStops: true,
        showInput: true,
        formatTooltip: (val) => {
            return (val * 100).toFixed(0) + '%';
        },
    }
}

Vertical Slider

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

Custom Marks

js
const rule = {
    type:"slider",
    field:"score",
    title:"Score",
    value:60,
    props:{
        min: 0,
        max: 100,
        marks: {
            0: '0 points',
            25: '25 points',
            50: '50 points',
            75: '75 points',
            100: '100 points'
        },
    }
}

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 (after drag end):', value);
        },
        input: (value) => {
            console.log('Value changed (real-time):', 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,
            showInput: true,
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Update price range display
                const [min, max] = value;
                $inject.api.setValue('priceRangeText', `¥${min} - ¥${max}`);
            },
        },
    },
    {
        type:"input",
        field:"priceRangeText",
        title:"Price Range",
        props: {
            disabled: true,
        },
    },
]

Full configuration: Element_Slider

value :Number | Array

Props

Attribute NameDescriptionTypeDefault
minMinimum valuenumber0
maxMaximum valuenumber100
disabledWhether to disablebooleanfalse
stepStep sizenumber1
showInputWhether to show input box. Only effective in non-range selectionbooleanfalse
showInputControlsWhen input box is shown, whether to show control buttons for input boxbooleantrue
sizeSize of slider wrapper. This property is not available in vertical modeenumdefault
inputSizeSize of input box. If size property is set, default value automatically takes sizeenumdefault
showStopsWhether to show stopsbooleanfalse
showTooltipWhether to show tooltip informationbooleantrue
formatTooltipFormat tooltip informationFunction
rangeWhether to enable range selectionbooleanfalse
verticalVertical modebooleanfalse
heightSlider height. Required in vertical modestring
ariaLabelNative aria-label attributestring
rangeStartLabelScreen reader label for start marker when range is truestring
rangeEndLabelScreen reader label for end marker when range is truestring
formatValueTextFormat for displaying aria-valuenow attribute for screen readerFunction
debounceDebounce delay for input, in milliseconds. Only effective when show-input equals truenumber300
tooltipClassCustom class name for tooltipstring
placementPosition where Tooltip appearsenumtop
marksMarks. Key type must be number and value must be in closed interval [min, max]. Each mark can have its own styleobject
validateEventWhether to trigger form validation on inputbooleantrue
persistentWhen slider's tooltip is inactive and persistent is false, Popconfirm will be destroyed. When show-tooltip is false, persistent will always be false.booleantrue

Events

Event NameDescriptionType
changeTriggered when value changes (when using mouse drag, only triggered after releasing mouse)Function
inputTriggered when data changes (when using mouse drag, triggered in real-time during the process)Function

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