JGuang

Slider

Slider · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Slider

A Slider component for displaying current value and intervals in range.

When To Use

Used to input a value within a specified range.

Examples

  • Basic · basic
  • Slider with InputNumber · input-number
  • Slider with icon · icon-slider
  • Customize tooltip · tip-formatter
  • Event · event
  • Graduated slider · mark
  • Vertical · vertical
  • Control visibility of Tooltip · show-tooltip
  • Reverse · reverse
  • Draggable track · draggableTrack
  • Multiple handles · multiple
  • Dynamic edit nodes · editable
  • Disabled per handle · disabled-handle
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersionGlobal Config
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.23.0
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 interactive. This prop can also be an array to disable specific handles in range mode, e.g. [true, false, true] disables first and third handles. When any rendered handle is disabled, editable mode will be disabledboolean | boolean[]false×
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 selectionboolean | rangefalse×
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>-5.23.0
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

Semantic nodeNative descriptionVersion
rootRoot element with relative positioning, height, margin, padding, cursor style and touch action control5.23.0
trackTrack selection bar element with absolute positioning, background color, border radius and transition animation styles5.10.0
tracksMulti-segment track container element with absolute positioning and transition animation styles5.10.0
railBackground rail element with absolute positioning, background color, border radius and transition animation styles5.10.0
handleSlider handle control element with absolute positioning, size, outline, user selection, background color, border shadow, border radius, cursor style and transition animation5.10.0

Semantic description source: vendor/components/slider/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
controlSizenumberHeight of slider
railSizenumberHeight of rail
handleSizenumberSize of handle
handleSizeHovernumberSize of handle when hover
handleLineWidthnumber | stringBorder width of handle
handleLineWidthHovernumber | stringBorder width of handle when hover
dotSizenumberSize of dot
railBgstringBackground color of rail
railHoverBgstringBackground color of rail when hover
trackBgstringBackground color of track
trackHoverBgstringBackground color of track when hover
handleColorstringColor of handle
handleActiveColorstringBorder color of handle when active
handleActiveOutlineColorstringOutline color of handle when active
handleColorDisabledstringColor of handle when disabled
dotBorderColorstringBorder color of dot
dotActiveBorderColorstringBorder color of dot when active
trackBgDisabledstringBackground color of track when disabled

Declaration source: vendor/components/slider/style/index.ts

import type * as React from 'react';

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { FastColor } from '@ant-design/fast-color';

import { resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

// Direction naming standard:
// Horizontal base:
// -0-------------
// vertical: part   (水平时,垂直方向命名为 part)
// horizontal: full (水平时,水平方向命名为 full)

export interface ComponentToken {
  /**
   * @desc 滑动输入高度
   * @descEN Height of slider
   */
  controlSize: number;
  /**
   * @desc 轨道高度
   * @descEN Height of rail
   */
  railSize: number;
  /**
   * @desc 滑块尺寸
   * @descEN Size of handle
   */
  handleSize: number;
  /**
   * @desc 滑块尺寸(悬浮态)
   * @descEN Size of handle when hover
   */
  handleSizeHover: number;
  /**
   * @desc 滑块边框宽度
   * @descEN Border width of handle
   */
  handleLineWidth: number | string;
  /**
   * @desc 滑块边框宽度(悬浮态)
   * @descEN Border width of handle when hover
   */
  handleLineWidthHover: number | string;
  /**
   * @desc 滑块圆点尺寸
   * @descEN Size of dot
   */
  dotSize: number;
  /**
   * @desc 轨道背景色
   * @descEN Background color of rail
   */
  railBg: string;
  /**
   * @desc 轨道背景色(悬浮态)
   * @descEN Background color of rail when hover
   */
  railHoverBg: string;
  /**
   * @desc 轨道已覆盖部分背景色
   * @descEN Background color of track
   */
  trackBg: string;
  /**
   * @desc 轨道已覆盖部分背景色(悬浮态)
   * @descEN Background color of track when hover
   */
  trackHoverBg: string;
  /**
   * @desc 滑块颜色
   * @descEN Color of handle
   */
  handleColor: string;
  /**
   * @desc 滑块激活态边框色
   * @descEN Border color of handle when active
   */
  handleActiveColor: string;
  /**
   * @desc 滑块激活态外框色
   * @descEN Outline color of handle when active
   */
  handleActiveOutlineColor: string;
  /**
   * @desc 滑块禁用颜色
   * @descEN Color of handle when disabled
   */
  handleColorDisabled: string;
  /**
   * @desc 圆点边框颜色
   * @descEN Border color of dot
   */
  dotBorderColor: string;
  /**
   * @desc 圆点激活态边框颜色
   * @descEN Border color of dot when active
   */
  dotActiveBorderColor: string;
  /**
   * @desc 轨道禁用态背景色
   * @descEN Background color of track when disabled
   */
  trackBgDisabled: string;
}

interface SliderToken extends FullToken<'Slider'> {
  marginFull: number | string;
  marginPart: number | string;
  marginPartWithMark: number | string;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/slider/Context.ts
  • vendor/components/slider/SliderTooltip.tsx
  • vendor/components/slider/index.tsx
  • vendor/components/slider/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.