Ant Design Svelte

Slider

Select the number and range limits on the scale.

When to use

Slider allows you to select a number within a range or multiple boundaries of a range. It is convenient when the position on the scale helps to understand the value: volume, price or threshold. For precise input, combine it with InputNumber, keeping the same state for both controls.

Sign the purpose of the scale and units of measurement. For a range, each point needs its own accessible name: for example, minimum and maximum price. The hover tooltip does not replace the field label.

Meaning and range of

Model depends on mode:

Problem Meaning and Setting Example
Select one number number, bind:value Number and range
Set boundaries range, number[] Number and range
Combine scale with precise input General numerical model Exact input with InputNumber
Edit multiple points range.editable Editing points

The defaultValue property specifies the initial local state. For subsequent changes, use value, bind:value or callback. range callbacks get a sorted copy of the array. An array can contain more than two points; do not limit the model type to a pair if the application uses multiple borders.

In range, the absence of an initial value creates two points at min. Explicit null and an empty array specify an empty scale. Maintain this distinction during initialization and reset; it is not equivalent to the single value 0.

Points and restrictions

Properties min and max limit the interval, positive step specifies the step. Match the step to the length of the interval. With step=null marks and min/max boundaries are available. Marks and step also shows included: space filling and individual marked positions.

In range, the draggableTrack setting moves the entire selected segment, maintaining the distance between the borders. editable adds a point by clicking on the scale and removes a point in focus via Delete; minCount/maxCount limit the quantity. editable takes precedence over draggableTrack. Moving a Range and editing are shown separately.

The properties allowCross and pushable regulate the movement of neighboring points. disabled can block the entire scale or individual points with a boolean array. Having an inaccessible point also blocks editing and dragging of the segment. Example of inaccessible points shows constraints without replacing the model array.

The orientation property changes the location of the scale; For the vertical Slider, set the height of the container. reverse changes direction. Check boundary labels and keyboard operation along with direction, as in reverse scale.

Events and Availability

The onChange handler reports changes during the action and is called before updating bind:value; onValueChange gets the value after the binding is updated. The onChangeComplete handler reports the completion of the action. Example Events shows change when the arrow is pressed and completion when the key is released. For a new value inside a callback, use its argument.

In range, completion can also occur for an action without changing the value; deleting via Delete does not call onChangeComplete. If saving is to be performed only on the new value, the application compares it with the previous one. Don't run expensive work on every movement unnecessarily.

Native points are accessible from the keyboard. keyboard=false disables key control while maintaining pointer interaction. For each point, use ariaLabelForHandle or ariaLabelledByForHandle; ariaValueTextFormatterForHandle reports the spoken value with units. For a single Slider, you can set an aria-label or associate a signature via FormItem.

The tooltip.formatter function returns text or a snippet for the visible tooltip. null disables the tooltip. tooltip.open controls its visibility. Tooltip format and visibility show different settings.

In Form, pass the value explicitly and update it via onValueChange. Volume shape shows check, send and reset. CSS styles and classNames classes for root, tracks, track, rail and handle are available for design; Semantic DOM and design tokens for Slider show them separately.

A non-empty local prefixCls specifies the CSS classes of the single/range scale. The empty string and undefined inherit ConfigProvider.prefixCls with the -slider suffix, defaulting to ant-slider. Tooltips separately enable tooltip.prefixCls, otherwise they inherit the common prefix with the -tooltip suffix. The scale's local prefix does not rename them. Changing classes preserves values, knobs and keyboard; CSS variables and canonical markers preserve names. Example ConfigProvider toggles between global and local prefix.

Examples

30; [20, 50]

Number and range

bind:value binds a number or array of bounds. disabled disables both scales.

Exact input with InputNumber

Slider and InputNumber use the same model: integer and fraction with increments of 0.01.

Icons around the edges

Symbols on the edges help you read the scale and change color relative to the middle.

Hint format

formatter returns a snippet with the current percentage. formatter={null} disables the second slider tooltip.

Change: 30; completion: —
[20,50]; completion: []

Change and completion

The binding is updated during movement, onChangeComplete is updated after the pointer or key is released.

included=true one point

Range with marks

included=false

marks and step=10

step=null · marks only

Marks and pitch

Five options with marks: one point, range, included=false, step 10 and selecting only marks with step=null. Markers are also supported in the numeric Slider.

Vertical scales

orientation="vertical" expands the number, range and scale with marks. The height is set explicitly.

Tooltip visibility

tooltip.open: undefined leaves automatic display, true fixes the tooltip, false hides it. Constant display is activated by a switch.

30; [20, 50]

Reverse direction

reverse reverses the direction of the numeric scale and range, including arrow control.

[20,50]

Range movement

range.draggableTrack allows you to move the entire selected segment while maintaining the distance between points.

[0,10,20]

Multiple points

The value array specifies three points. styles.tracks draws a general gradient, individual tracks are transparent.

[20,80]

Editing points

Click on the scale to add a point; Delete deletes the point in focus. minCount=1 and maxCount=5 limit their number.

[20,50,80]

Inaccessible points

The disabled array blocks individual points. A blocked point becomes a boundary for neighboring ones; editable and draggableTrack are also disabled.

Semantic styles

The styles object and function from { props } set CSS strings for track and handle in both modes; the range is shown here.

Step 5: To test the shape, keep the value between 10 and 90.

Applied: 40%.

Volume and check in Form

Scale and precision input are associated with Form. Check, Dispatch, Reset, Direct, and Availability use the same example as Review.

API

The main parameters are checked with the public types of the installed @woodger/antd. Numeric Slider and range have different contracts; an array with one point remains in range mode.

Main parameters of Slider
PropertyDescriptionTypeDefault
prefixClsFull local CSS scale prefix single/range; Tooltips resolve their prefix separately. The empty string and undefined inherit ConfigProvider.prefixCls; default ant-slider.stringConfigProvider + -slider
valuebind:value: number without range, array or null with range. Range callbacks receive a sorted copy of the array.number | number[] | nullFrom defaultValue
defaultValueInitial value. For range, undefined creates two points, null and [] - none; an array of one number creates one point.number | number[] | null0 / [min, min]
rangeSelects a numeric model or array. The object includes editing points and moving a segment.false | true | SliderRangeConfigfalse
minLower limit of values.number0
maxUpper limit of values.number100
stepA positive step. null limits the selection to marks, min and max in both modes.number | null1
disabledLocks the scale or individual range points. For a numeric Slider, the first element of the array is taken into account. Inherits the availability of Form and ConfigProvider.boolean | readonly boolean[]From context
orientationScale direction. Set the height of the vertical scale using style.horizontal | verticalhorizontal
reverseExpands the scale and arrow controls; the horizontal scale also takes into account RTL.booleanfalse
keyboardArrow control, Home and End. Disabling does not remove the dot from the Tab order.booleantrue
tooltipVisibility, position, container and value format. false hides the tooltip completely.false | SliderTooltipConfigAutomatic display
onValueChangeGets the new value of the corresponding mode. To bind state use bind:value.(value: number | number[]) => void—
onChangeGets a number or array before updating bind:value; onValueChange is called after. Native onchange receives a DOM event.(value: number | number[]) => void—
onChangeCompleteEnd interaction with the pointer or navigation key. Canceling does not post completion.(value: number | number[]) => void—
refbind:ref provides focus(), blur() and nativeElement after mount.SliderRef—
nativeElementbind:nativeElement returns the root container.HTMLDivElement—
Elevations, range and Slider styles
PropertyDescriptionTypeDefault
marksNumeric label labels: text, number, snippet or object { label, style }. style — CSS string.SliderMarks—
dotsShows marks for each step.booleanfalse
includedEnables filling between points; if false, the marks are highlighted independently.booleantrue
allowCrossAllows points to intersect. Inaccessible points remain impassable boundaries.booleantrue
pushablePushes adjacent points to maintain distance. true uses step; step=null — adjacent marks.boolean | numberfalse
classNamesClasses root, rail, tracks, track and handle.SliderClassNames | ({ props }) => SliderClassNames—
stylesCSS strings of semantic elements; object or function from current props.SliderStyles | ({ props }) => SliderStyles—
ariaLabelForHandleAvailable name for each point. There is also ariaLabelledByForHandle and ariaValueTextFormatterForHandle.string | readonly string[]From the Form context
Range object settings
PropertyDescriptionTypeDefault
draggableTrackMoves the selected segment while maintaining the distance between its boundaries.booleanfalse
editableAdding and deleting points. Takes precedence over draggableTrack; inaccessible points block both modes.booleanfalse
minCountMinimum number of points when editing.number0
maxCountMaximum number of points when editing.numberNo limit
Tooltip settings
PropertyDescriptionTypeDefault
prefixClsFull local CSS tooltip prefix for all single/range handles; the local scale prefix does not affect them. The empty string and undefined inherit ConfigProvider.prefixCls; default ant-tooltip.stringConfigProvider + -tooltip
autoAdjustOverflowCorrects the position at the edge of the window. The { adjustX, adjustY } object controls axis adjustment.boolean | AdjustOverflowtrue
opentrue - always show, false - always hide, undefined - show during interaction.booleanundefined
formatterFormats the value. The function can return text or a snippet. null disables the tooltip, and returning null hides it for the current value.((value: number) => TooltipContent) | nullString(value)
triggerEvents that show and hide the tooltip. Set delays with mouseEnterDelay, mouseLeaveDelay, focusDelay, and blurDelay.TooltipProps["trigger"]—
afterOpenChangeRuns for each handle tooltip when its animation finishes.(open: boolean) => void—
placementTooltip position relative to the point.TooltipPlacementIn scale direction
arrowArrow display and alignment.boolean | { pointAtCenter?: boolean }true
getPopupContainerTooltip container specified via tooltip.getPopupContainer.(trigger: HTMLElement) => HTMLElementdocument.body

marks, dots, included, step=null, classNames, styles and onChange is supported in numeric Slider and range. To bind use bind:value; native onchange receives a DOM event.

ConfigProvider.slider specifies class, style, classNames and styles for both modes. orientation selects direction; semantic styles are used for decoration, to complete the change - onChangeComplete.

Tooltip formatter returns a string or null, not arbitrary markup. color, prefixCls, openClassName and destroyOnHidden are also available. The main themes of the examples were checked against ant.design 6.7.0; The basic version of the library transfer is 6.6.8.

Methods

Use bind:ref for focus(), blur() and nativeElement. For a range, focus refers to the first point. Methods are not exported via bind:this.

<script lang="ts">
  import { Button, Slider, type SliderRef } from '@woodger/antd';

  let ref = $state<SliderRef>();
</script>

<style>
  .example {
    display: grid;
    gap: 20px;
  }
  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

<div class="example">
  <Slider bind:ref defaultValue={30} aria-label={("Slider Methods")} />
  <div class="actions">
    <Button onclick={() => ref?.focus()}>{("Focus Slider")}</Button>
    <Button onclick={() => ref?.blur()}>{("Remove Focus Slider")}</Button>
  </div>
</div>

Semantic DOM

Select an element to highlight. Five names are available in classNames and styles of both modes. tracks designs the general layer, track - individual segments. styles accepts CSS strings or a function from { props }.

root: Root container of the scale.

Registration tokens

18 component tokens are specified in ConfigProvider.theme.components.Slider. They are listed in the public type ComponentTokenMap['Slider'] and applied to the numeric Slider and range.

In the example, the local theme sets the bar width to 6 px, the point size to 12 px, and the colors green. The rest of the Slider on the page maintains the overall theme. For individual scale elements are also available semantic styles.

Numeric Slider

Range

<script lang="ts">
  import { ConfigProvider, Slider } from '@woodger/antd';
</script>

<style>
  .example {
    display: grid;
    gap: 24px;
  }
  p {
    margin: 0 0 12px;
    color: var(--ant-color-text-secondary);
  }
</style>

<ConfigProvider theme={{
  cssVar: {},
  components: {
    Slider: {
      railSize: 6,
      handleSize: 12,
      trackBg: '#73d13d',
      trackHoverBg: '#52c41a',
      handleColor: '#389e0d',
      handleActiveColor: '#237804'
    }
  }
}}>
  <div class="example">
    <div>
      <p>{("Numeric Slider")}</p>
      <Slider defaultValue={30} class="slider-token-single" aria-label={("Custom Slider theme")} />
    </div>
    <div>
      <p>{("Range")}</p>
      <Slider range defaultValue={[25, 75]} classNames={{ root: 'slider-token-range' }}
        ariaLabelForHandle={["Own theme Slider start", "Own theme Slider end"]} />
    </div>
  </div>
</ConfigProvider>
Component Slider Tokens
TokenPurpose
controlSizeScale area size.
dotActiveBorderColorActive mark outline.
dotBorderColorOutline of a regular mark.
dotSizeMark size.
handleActiveColorContour of the active point.
handleActiveOutlineColorExternal contour of the active point.
handleColorContour of a regular point.
handleColorDisabledOutline of an inaccessible point.
handleLineWidthPoint outline thickness.
handleLineWidthHoverOutline thickness when hovering.
handleSizePoint size.
handleSizeHoverPoint size when hovering.
railBgScale background.
railHoverBgBackground of the scale when hovering.
railSizeScale strip thickness.
trackBgBackground of the selected segment.
trackBgDisabledBackground of the inaccessible segment.
trackHoverBgBackground of the selected segment when hovering.

Common tokens of the current topic

13 common tokens from the Slider table are read through theme.useToken() and react to the settings in the header.

Common tokens of the current topic
TokenPurposeCurrent value
colorBgElevatedPop-up layer background.#ffffff
colorFillContentHoverFill on hover.rgba(0,0,0,0.15)
colorPrimaryBorderHoverMain contour when hovering.#85a5ff
colorTextText color.rgba(0,0,0,0.88)
colorTextDescriptionColor descriptions.rgba(0,0,0,0.45)
borderRadiusXSSmall rounding.2
controlHeightNormal element height.32
controlHeightLGHeight of large elements.40
fontFamilyFont family.-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSizeText size.14
lineHeightRow height.1.5714285714285714
motionDurationMidDuration of main transitions.0.2s
motionDurationSlowDuration of slow transitions.0.3s

FAQ

When to use onChangeComplete?

To process a completed action after releasing the pointer or key. While moving, use bind:value or onValueChange. In range, completion does not necessarily mean changing the value, and Delete is handled separately. Example Events shows both points.

How to select only signed marks?

Set marks and step=null. Acceptable positions also remain min/max. The model of a numeric Slider is a number, while that of a range is an array. Example of marks compares the step and fill of the scale.

How to add or remove a point?

Enable range.editable. Clicking on the scale adds a point, Delete deletes a point in focus. The minCount/maxCount settings set the limits; inaccessible points block editing. editable takes precedence over draggableTrack.

How to sign several points for a screen reader?

Pass an array of ariaLabelForHandle or ariaLabelledByForHandle, and for the spoken value, ariaValueTextFormatterForHandle. A single Slider only needs an aria-label or a connection to a FormItem.

Why do [] and undefined give different numbers of points?

In range, the absence of an initial value creates two points at min. Explicit null and an empty array specify an empty scale. Maintain this distinction in the original model and when resetting it.