Back to Element Plus

Slider

docs/en-US/component/slider.md

2.13.711.9 KB
Original Source

Slider

Drag the slider within a fixed range.

Basic usage

The current value is displayed when the slider is being dragged.

:::demo Customize the initial value of the slider by setting the binding value.

slider/basic-usage

:::

Discrete values

The options can be discrete.

:::demo Set step size with the step attribute. You can display breakpoints by setting the show-stops attribute.

slider/discrete-values

:::

Slider with input box

Set value via a input box.

:::demo Set the show-input attribute to display an input box on the right.

slider/slider-with-input-box

:::

Sizes

:::demo

slider/sizes

:::

Placement

You can custom tooltip placement.

:::demo

slider/placement

:::

Range selection

Selecting a range of values is supported.

:::demo Setting the range attribute activates range mode, where the binding value is an array made up of two boundary values.

slider/range-selection

:::

Vertical mode

:::demo Setting the vertical attribute to true enables vertical mode. In vertical mode, the height attribute is required.

slider/vertical-mode

:::

Show marks

:::demo Setting this marks attribute can show mark on slider.

slider/show-marks

:::

Restrict value ^(2.13.6)

:::demo Set step="mark" to restrict the slider value to marks.

slider/restrict-value

:::

API

Attributes

NameDescriptionTypeDefault
model-value / v-modelbinding value^[number] / ^[array]number[]0
minminimum value^[number]0
maxmaximum value^[number]100
disabledwhether Slider is disabled^[boolean]false
stepstep size, can be a number or 'mark' ^(2.13.6) to restrict values to marks. When set to 'mark', the marks attribute must be set^[number] / ^[string]'mark'1
show-inputwhether to display an input box, works when range is false and step is not 'mark'^[boolean]false
show-input-controlswhether to display control buttons when show-input is true^[boolean]true
sizesize of the slider wrapper, will not work in vertical mode^[enum]'' | 'large' | 'default' | 'small'default
input-sizesize of the input box, when set size, the default is the value of size^[enum]'' | 'large' | 'default' | 'small'default
show-stopswhether to display breakpoints^[boolean]false
show-tooltipwhether to display tooltip value^[boolean]true
format-tooltipformat to display tooltip value^[Function](value: number) => number | string��
rangewhether to select a range^[boolean]false
verticalvertical mode^[boolean]false
heightslider height, required in vertical mode^[string]
aria-label ^(a11y) ^(2.7.2)native aria-label attribute^[string]
range-start-labelwhen range is true, screen reader label for the start of the range^[string]
range-end-labelwhen range is true, screen reader label for the end of the range^[string]
format-value-textformat to display the aria-valuenow attribute for screen readers^[Function](value: number) => string
tooltip-classcustom class name for the tooltip^[string]
placementposition of Tooltip^[enum]'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end'top
marksmarks, type of key must be number and must in closed interval [min, max], each mark can custom style^[object]SliderMarks
validate-eventwhether to trigger form validation^[boolean]true
persistent ^(2.9.5)when slider tooltip inactive and persistent is false , tooltip will be destroyed. persistent always be false when show-tooltip is false^[boolean]true
label ^(a11y) ^(deprecated)native aria-label attribute^[string]

Events

NameDescriptionType
changetriggers when the value changes (if the mouse is being dragged, this event only fires when the mouse is released)^[Function](value: Arrayable<number>) => boolean
inputtriggers when the data changes (It'll be emitted in real time during sliding)^[Function](value: Arrayable<number>) => boolean

Type Declarations

<details> <summary>Show declarations</summary>
ts
type SliderMarks = Record<number, string | { style: CSSProperties; label: any }>
type Arrayable<T> = T | T[]
</details>