Back to Ant Design

Slider

components/slider/index.en-US.md

6.3.75.4 KB
Original Source

When To Use

Used to input a value within a specified range.

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/input-number.tsx">Slider with InputNumber</code> <code src="./demo/icon-slider.tsx">Slider with icon</code> <code src="./demo/tip-formatter.tsx">Customize tooltip</code> <code src="./demo/event.tsx">Event</code> <code src="./demo/mark.tsx">Graduated slider</code> <code src="./demo/vertical.tsx">Vertical</code> <code src="./demo/show-tooltip.tsx">Control visibility of Tooltip</code> <code src="./demo/reverse.tsx">Reverse</code> <code src="./demo/draggableTrack.tsx">Draggable track</code> <code src="./demo/multiple.tsx">Multiple handles</code> <code src="./demo/editable.tsx" version="5.20.0">Dynamic edit nodes</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
defaultValueThe default value of the slider. When range is false, use number, otherwise, use [number, number]number | [number, number]0 | [0, 0]
disabledIf true, the slider will not be interactivebooleanfalse
keyboardSupport using keyboard to move handlersbooleantrue5.2.0+
dotsWhether the thumb can only be dragged to tick marksbooleanfalse
includedTakes effect when marks is not null. True means containment and false means coordinativebooleantrue
marksTick marks of Slider. The type of key must be number, and must be in closed interval [min, max]. Each mark can declare its own styleobject{ number: ReactNode } | { number: { style: CSSProperties, label: ReactNode } }
maxThe maximum value the slider can slide tonumber100
minThe minimum value the slider can slide tonumber0
orientationOrientationhorizontal | verticalhorizontal
rangeEnable dual thumb mode for range selectionbooleanfalse
reverseReverse the componentbooleanfalse
stepThe granularity the slider can step through values. Must be greater than 0, and be divisible by (max - min). When step is null and marks exist, valid points will only be marks, min and maxnumber | null1
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
tooltipThe tooltip related propstooltip-4.23.0
valueThe value of slider. When range is false, use number, otherwise, use [number, number]number | [number, number]-
verticalIf true, the slider will be vertical. Simultaneously existing with orientation, orientation takes prioritybooleanfalse
onChangeCompleteFire when mouseup or keyup is fired(value) => void-
onChangeCallback function that is fired when the user changes the slider's value(value) => void-
handleStyleStyle of the slider handle, please use styles.handle insteadCSSProperties--
onAfterChangeCallback fired when mouseup or keyup is fired, please use onChangeComplete instead(value) => void--
railStyleStyle of the slider rail, please use styles.rail insteadCSSProperties--
trackStyleStyle of the slider track, please use styles.track insteadCSSProperties--

range

PropertyDescriptionTypeDefaultVersion
draggableTrackWhether range track can be draggedbooleanfalse-
editableDynamic edit nodes. Cannot be used with draggableTrackbooleanfalse5.20.0
minCountThe minimum count of nodesnumber05.20.0
maxCountThe maximum count of nodesnumber-5.20.0

tooltip

PropertyDescriptionTypeDefaultVersion
autoAdjustOverflowWhether to automatically adjust the popup positionbooleantrue5.8.0
openIf true, Tooltip will always be visible; if false, it will never be visible, even when dragging or hoveringboolean-4.23.0
placementSet Tooltip display position. Ref Tooltipstring-4.23.0
getPopupContainerThe DOM container of the Tooltip. The default behavior is to create a div element in the body(triggerNode) => HTMLElement() => document.body4.23.0
formatterSlider will pass its value to formatter, display its value in Tooltip, and hide the Tooltip when the returned value is nullvalue => ReactNode | nullIDENTITY4.23.0

Methods

NameDescriptionVersion
blur()Remove focus
focus()Get focus

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Slider"></ComponentTokenTable>