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
Number and range
bind:value binds a number or array of bounds. disabled disables both scales.
<script lang="ts">
import { Checkbox, Slider } from '@woodger/antd';
let disabled = $state(false);
let value = $state(30);
let range = $state<number[]>([20, 50]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Slider bind:value {disabled} aria-label={("Basic Slider")} />
<Slider range bind:value={range} {disabled}
ariaLabelForHandle={["Basic range start", "Base range end"]} />
<Checkbox bind:checked={disabled}>{("Unavailable Slider")}</Checkbox>
<output
aria-label={("Basic values Slider")}
>{value}; [{range.join(', ')}]</output>
</div>
Exact input with InputNumber
Slider and InputNumber use the same model: integer and fraction with increments of 0.01.
<script lang="ts">
import { InputNumber, Slider } from '@woodger/antd';
let integer = $state(1);
let decimal = $state(0.1);
</script>
<style>
.example {
display: grid;
gap: 24px;
}
.row {
display: grid;
grid-template-columns: minmax(0, 1fr) 96px;
align-items: center;
gap: 20px;
}
</style>
<div class="example">
<div class="row">
<Slider
min={0}
max={20}
bind:value={integer}
aria-label={("Integer value Slider")}
/>
<InputNumber min={0} max={20} value={integer} onValueChange={value => { integer = value ?? 0; }}
aria-label={("Exact integer value")} style="width:100%" />
</div>
<div class="row">
<Slider min={0} max={1} step={0.01} bind:value={decimal} aria-label={("Fractional value Slider")} />
<InputNumber min={0} max={1} step={0.01} precision={2} value={decimal}
onValueChange={value => { decimal = value ?? 0; }} aria-label={("Exact fractional value")}
style="width:100%" />
</div>
</div>
Icons around the edges
Symbols on the edges help you read the scale and change color relative to the middle.
<script lang="ts">
import { Slider } from '@woodger/antd';
let value = $state(10);
</script>
<style>
.row {
display: grid;
grid-template-columns: 16px minmax(0, 1fr) 16px;
align-items: center;
gap: 12px;
}
span {
color: var(--ant-color-text-secondary);
font-size: 20px;
text-align: center;
}
.active { color: var(--ant-color-primary); }
</style>
<div class="row">
<span aria-hidden="true" class:active={value < 10}>−</span>
<Slider min={0} max={20} bind:value aria-label={("Signal level")} />
<span aria-hidden="true" class:active={value > 10}>+</span>
</div>
Hint format
formatter returns a snippet with the current percentage. formatter={null} disables the second slider tooltip.
<script lang="ts">
import { Slider } from '@woodger/antd';
let percent = $state(30);
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
{#snippet percentage()}<strong>{percent}%</strong>{/snippet}
<div class="example">
<Slider bind:value={percent} aria-label={("Percentage Slider")}
tooltip={{ formatter: () => percentage }} />
<Slider defaultValue={30} aria-label={("Slider without formatter")}
tooltip={{ formatter: null }} />
</div>
Change and completion
The binding is updated during movement, onChangeComplete is updated after the pointer or key is released.
<script lang="ts">
import { Slider } from '@woodger/antd';
let value = $state(30);
let completed = $state<number>();
let range = $state<number[]>([20, 50]);
let completedRange = $state<number[]>([]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<Slider bind:value onChangeComplete={next => { completed = next; }} aria-label={("Number Slider Events")} />
<output aria-label={("Number events")}>{("Change: ")}{value}{("; completion: ")}{(completed
?? '—')}</output>
<Slider range bind:value={range} onChangeComplete={next => { completedRange = next; }}
ariaLabelForHandle={["Range events start", "Events range end"]} />
<output aria-label={("Range Events")}>{JSON.stringify(range)}{("; completion: ")}{JSON
.stringify(completedRange)}</output>
</div>
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.
<script lang="ts">
import { Slider, type SliderMarks } from '@woodger/antd';
const marks = {
0: '0°C',
26: '26°C',
37: '37°C',
100: { label: '100°C', style: `
color: var(--ant-color-error);
font-weight: 700;
` }
} satisfies SliderMarks;
let discrete = $state<number[]>([37]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.field { padding-bottom: 24px; }
p {
margin: 0 0 16px;
color: var(--ant-color-text-secondary);
}
</style>
<div class="example">
<div class="field">
<p>{("included=true one point")}</p>
<Slider range marks={(marks)} defaultValue={[37]} ariaLabelForHandle={("Single dot with marks")} />
</div>
<div class="field"><p>{("Range with marks")}</p>
<Slider range marks={(marks)} defaultValue={[26, 37]} ariaLabelForHandle={[
"Marks start",
"End marks"
]} />
</div>
<div class="field"><p>included=false</p>
<Slider
range
marks={(marks)}
included={false}
defaultValue={[37]}
ariaLabelForHandle={("Independent marks")}
/>
</div>
<div class="field"><p>{("marks and step=10")}</p>
<Slider
range
marks={(marks)}
step={10}
defaultValue={[37]}
ariaLabelForHandle={("Marks and pitch")}
/>
</div>
<div class="field"><p>{("step=null · marks only")}</p>
<Slider
range
marks={(marks)}
step={null}
bind:value={discrete}
ariaLabelForHandle={("Marks only")}
/>
</div>
</div>
Vertical scales
orientation="vertical" expands the number, range and scale with marks. The height is set explicitly.
<script lang="ts">
import { Slider } from '@woodger/antd';
const marks = { 0: '0°C', 26: '26°C', 37: '37°C', 100: '100°C' };
</script>
<style>
.columns {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 24px;
}
.field {
display: flex;
justify-content: center;
padding-block: 10px;
min-height: 220px;
}
</style>
<div class="columns">
<div class="field"><Slider orientation="vertical" defaultValue={30} style="height:180px"
aria-label={("Vertical number")} /></div>
<div
class="field"
><Slider
range
orientation="vertical"
defaultValue={[20, 50]}
style="height:180px"
ariaLabelForHandle={["Vertical range start", "Vertical range end"]}
/></div>
<div
class="field"
><Slider
range
orientation="vertical"
marks={(marks)}
defaultValue={[26, 37]}
style="height:180px"
ariaLabelForHandle={["Start temperature", "Temperature end"]}
/></div>
</div>
Tooltip visibility
tooltip.open: undefined leaves automatic display, true fixes the tooltip, false hides it. Constant display is activated by a switch.
<script lang="ts">
import { RadioGroup, Slider, type RadioOption } from '@woodger/antd';
let mode = $state<'auto' | 'open' | 'closed'>('auto');
const options: RadioOption<typeof mode>[] = [
{ value: 'auto', label: "Auto" },
{ value: 'open', label: "Show" },
{ value: 'closed', label: "Hide" }
];
</script>
<style>
.example {
display: grid;
gap: 32px;
}
</style>
<div class="example">
<RadioGroup aria-label={("Visibility Tooltip Slider")} options={(options)} bind:value={mode} />
<Slider defaultValue={30} aria-label={("Control Tooltip")} tooltip={({
open: mode === 'auto' ? undefined : mode === 'open',
formatter: value => `Meaning ${value}`
})} />
</div>
Reverse direction
reverse reverses the direction of the numeric scale and range, including arrow control.
<script lang="ts">
import { Checkbox, Slider } from '@woodger/antd';
let reverse = $state(true);
let value = $state(30);
let range = $state<number[]>([20, 50]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Slider {reverse} bind:value aria-label={("Reverse Number Slider")} />
<Slider range {reverse} bind:value={range} ariaLabelForHandle={[
"Reverse range start",
"Reverse range end"
]} />
<Checkbox bind:checked={reverse}>{("Reverse Direction Slider")}</Checkbox>
<output
aria-label={("Reverse Values Slider")}
>{value}; [{range.join(', ')}]</output>
</div>
Range movement
range.draggableTrack allows you to move the entire selected segment while maintaining the distance between points.
<script lang="ts">
import { Slider } from '@woodger/antd';
let value = $state<number[]>([20, 50]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Slider range={{ draggableTrack: true }} bind:value classNames={{ track: 'demo-draggable-track' }}
ariaLabelForHandle={["Drag start", "Drag end"]} />
<output aria-label={("Moved range")}>{JSON.stringify(value)}</output>
</div>
Multiple points
The value array specifies three points. styles.tracks draws a general gradient, individual tracks are transparent.
<script lang="ts">
import { Slider } from '@woodger/antd';
let value = $state<number[]>([0, 10, 20]);
function color(point: number) {
const ratio = point / 100;
return `rgb(${Math.round(135 + 120 * ratio)},${Math.round(208 - 4 * ratio)},${Math.round(
104 + 95 * ratio
)})`;
}
const background = $derived(`background:linear-gradient(to right,${color(value[0] ?? 0)},${color(
value.at(
-1
) ?? 0
)})`);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Slider range bind:value styles={{ track: 'background:transparent', tracks: background }}
classNames={{ tracks: 'demo-gradient-tracks' }} ariaLabelForHandle={[
"Point 1",
"Point 2",
"Point 3"
]} />
<output aria-label={("Multiple points Slider")}>{JSON.stringify(value)}</output>
</div>
Editing points
Click on the scale to add a point; Delete deletes the point in focus. minCount=1 and maxCount=5 limit their number.
<script lang="ts">
import { Slider } from '@woodger/antd';
let value = $state<number[]>([20, 80]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<Slider range={{ editable: true, minCount: 1, maxCount: 5 }} bind:value
classNames={{ root: 'demo-editable-slider' }} ariaLabelForHandle={[
"Editable point 1", "Editable point 2", "Editable point 3",
"Editable point 4", "Editable point 5"
]} />
<output aria-label={("Editable Slider Points")}>{JSON.stringify(value)}</output>
</div>
Inaccessible points
The disabled array blocks individual points. A blocked point becomes a boundary for neighboring ones; editable and draggableTrack are also disabled.
<script lang="ts">
import { Checkbox, Slider } from '@woodger/antd';
let disabled = $state([false, false, false]);
let value = $state<number[]>([20, 50, 80]);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<div class="controls">{#each disabled as _, index (index)}
<Checkbox bind:checked={disabled[index]}>{("Disable point ")}{(index + 1)}</Checkbox>
{/each}</div>
<Slider range bind:value {disabled} ariaLabelForHandle={[
"Restricted point 1",
"Restricted point 2",
"Restricted point 3"
]} />
<output aria-label={("Limited Points Slider")}>{JSON.stringify(value)}</output>
</div>
Semantic styles
The styles object and function from { props } set CSS strings for track and handle in both modes; the range is shown here.
<script lang="ts">
import { Checkbox, Slider, type SliderRangeProps } from '@woodger/antd';
let disabled = $state(false);
const styles: SliderRangeProps['styles'] = ({ props }) => ({
track: 'background:var(--ant-color-success)',
handle: props.disabled === true
? 'opacity:.5'
: 'box-shadow:0 0 0 2px var(--ant-color-success)'
});
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Slider range defaultValue={[20, 50]} styles={{ track: 'background:var(--ant-color-warning)' }}
ariaLabelForHandle={["Styles object start", "Styles object end"]} />
<Slider range defaultValue={[30, 70]} {styles} {disabled}
ariaLabelForHandle={["Styles function start", "Styles function end"]} />
<Checkbox bind:checked={disabled}>{("Disable Slider with styles function")}</Checkbox>
</div>
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.
<script lang="ts">
import { Button, Checkbox, Form, FormItem, InputNumber, Slider, createForm } from '@woodger/antd';
const generatedId = $props.id();
let vertical = $state(false);
let reverse = $state(false);
let disabled = $state(false);
let applied = $state(40);
let result = $state('');
const form = createForm({
initialValues: { volume: 40 },
rules: ({
volume: [
{
min: 10,
max: 90,
message: "To save, select the volume from 10 to 90."
}
]
})
});
function setVolume(value: number | null | undefined) {
form.setFieldValue('volume', value ?? 0);
result = '';
}
</script>
<style>
.example { max-width: 640px; }
.settings, .actions {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
}
.settings { margin-bottom: 24px; }
.pair {
display: grid;
grid-template-columns: minmax(0, 1fr) 130px;
gap: 24px;
}
.vertical {
display: flex;
justify-content: center;
}
.exact label {
display: block;
margin-bottom: 8px;
}
.applied {
margin: 0 0 24px;
color: var(--ant-color-text-secondary);
}
.result {
margin: 16px 0 0;
color: var(--ant-color-success);
}
@media (max-width: 560px) {
.pair {
grid-template-columns: minmax(0, 1fr);
gap: 0;
}
.exact {
margin-bottom: 24px;
}
}
</style>
<div class="example">
<div class="settings">
<Checkbox bind:checked={vertical}>{("Vertical arrangement")}</Checkbox>
<Checkbox bind:checked={reverse}>{("Reverse direction")}</Checkbox>
<Checkbox bind:checked={disabled}>{("Not available")}</Checkbox>
</div>
<Form
{form}
{disabled}
onFinish={(values) => {
result = ("Volume saved: " + String((values.volume)) + "%.");
}}
>
<div class="pair">
<FormItem
name="volume"
label={("Notification volume")}
help={("Step 5: To test the shape, keep the value between 10 and 90.")}
>
<div class:vertical><Slider
value={form.values.volume}
onValueChange={setVolume}
onChangeComplete={(value) => { applied = value; }}
step={5}
orientation={vertical ? 'vertical' : 'horizontal'}
{reverse}
tooltip={({ formatter: (value) => `${value}%` })}
style={vertical ? 'height: 160px' : undefined}
/></div>
</FormItem>
<div class="exact">
<label for={`slider-exact-${generatedId}`}>{("Accurate volume")}</label>
<InputNumber
id={`slider-exact-${generatedId}`}
bind:value={() => form.values.volume, setVolume}
min={0}
max={100}
step={5}
precision={0}
style="width: 100%"
onblur={() => { applied = form.values.volume; }}
/>
</div>
</div>
<p class="applied" role="status" aria-label={("Applied volume")}>{("Applied: ")}{applied}%.</p>
<div
class="actions"
><Button
type="primary"
htmlType="submit"
loading={form.isSubmitting}
>{("Save volume")}</Button><Button
htmlType="reset"
onclick={() => {
result = '';
applied = 40;
}}
>{("Reset volume")}</Button></div>
</Form>
{#if result}
<p class="result" role="status" aria-label={("Volume adjustment result")}>
{result}
</p>
{/if}
</div>
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.
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS scale prefix single/range; Tooltips resolve their prefix separately. The empty string and undefined inherit ConfigProvider.prefixCls; default ant-slider. | string | ConfigProvider + -slider |
value | bind:value: number without range, array or null with range. Range callbacks receive a sorted copy of the array. | number | number[] | null | From defaultValue |
defaultValue | Initial value. For range, undefined creates two points, null and [] - none; an array of one number creates one point. | number | number[] | null | 0 / [min, min] |
range | Selects a numeric model or array. The object includes editing points and moving a segment. | false | true | SliderRangeConfig | false |
min | Lower limit of values. | number | 0 |
max | Upper limit of values. | number | 100 |
step | A positive step. null limits the selection to marks, min and max in both modes. | number | null | 1 |
disabled | Locks 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 |
orientation | Scale direction. Set the height of the vertical scale using style. | horizontal | vertical | horizontal |
reverse | Expands the scale and arrow controls; the horizontal scale also takes into account RTL. | boolean | false |
keyboard | Arrow control, Home and End. Disabling does not remove the dot from the Tab order. | boolean | true |
tooltip | Visibility, position, container and value format. false hides the tooltip completely. | false | SliderTooltipConfig | Automatic display |
onValueChange | Gets the new value of the corresponding mode. To bind state use bind:value. | (value: number | number[]) => void | — |
onChange | Gets a number or array before updating bind:value; onValueChange is called after. Native onchange receives a DOM event. | (value: number | number[]) => void | — |
onChangeComplete | End interaction with the pointer or navigation key. Canceling does not post completion. | (value: number | number[]) => void | — |
ref | bind:ref provides focus(), blur() and nativeElement after mount. | SliderRef | — |
nativeElement | bind:nativeElement returns the root container. | HTMLDivElement | — |
| Property | Description | Type | Default |
|---|---|---|---|
marks | Numeric label labels: text, number, snippet or object { label, style }. style — CSS string. | SliderMarks | — |
dots | Shows marks for each step. | boolean | false |
included | Enables filling between points; if false, the marks are highlighted independently. | boolean | true |
allowCross | Allows points to intersect. Inaccessible points remain impassable boundaries. | boolean | true |
pushable | Pushes adjacent points to maintain distance. true uses step; step=null — adjacent marks. | boolean | number | false |
classNames | Classes root, rail, tracks, track and handle. | SliderClassNames | ({ props }) => SliderClassNames | — |
styles | CSS strings of semantic elements; object or function from current props. | SliderStyles | ({ props }) => SliderStyles | — |
ariaLabelForHandle | Available name for each point. There is also ariaLabelledByForHandle and ariaValueTextFormatterForHandle. | string | readonly string[] | From the Form context |
| Property | Description | Type | Default |
|---|---|---|---|
draggableTrack | Moves the selected segment while maintaining the distance between its boundaries. | boolean | false |
editable | Adding and deleting points. Takes precedence over draggableTrack; inaccessible points block both modes. | boolean | false |
minCount | Minimum number of points when editing. | number | 0 |
maxCount | Maximum number of points when editing. | number | No limit |
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full 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. | string | ConfigProvider + -tooltip |
autoAdjustOverflow | Corrects the position at the edge of the window. The { adjustX, adjustY } object controls axis adjustment. | boolean | AdjustOverflow | true |
open | true - always show, false - always hide, undefined - show during interaction. | boolean | undefined |
formatter | Formats 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) | null | String(value) |
trigger | Events that show and hide the tooltip. Set delays with mouseEnterDelay, mouseLeaveDelay, focusDelay, and blurDelay. | TooltipProps["trigger"] | — |
afterOpenChange | Runs for each handle tooltip when its animation finishes. | (open: boolean) => void | — |
placement | Tooltip position relative to the point. | TooltipPlacement | In scale direction |
arrow | Arrow display and alignment. | boolean | { pointAtCenter?: boolean } | true |
getPopupContainer | Tooltip container specified via tooltip.getPopupContainer. | (trigger: HTMLElement) => HTMLElement | document.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 }.
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>
| Token | Purpose |
|---|---|
controlSize | Scale area size. |
dotActiveBorderColor | Active mark outline. |
dotBorderColor | Outline of a regular mark. |
dotSize | Mark size. |
handleActiveColor | Contour of the active point. |
handleActiveOutlineColor | External contour of the active point. |
handleColor | Contour of a regular point. |
handleColorDisabled | Outline of an inaccessible point. |
handleLineWidth | Point outline thickness. |
handleLineWidthHover | Outline thickness when hovering. |
handleSize | Point size. |
handleSizeHover | Point size when hovering. |
railBg | Scale background. |
railHoverBg | Background of the scale when hovering. |
railSize | Scale strip thickness. |
trackBg | Background of the selected segment. |
trackBgDisabled | Background of the inaccessible segment. |
trackHoverBg | Background 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.
| Token | Purpose | Current value |
|---|---|---|
colorBgElevated | Pop-up layer background. | #ffffff |
colorFillContentHover | Fill on hover. | rgba(0,0,0,0.15) |
colorPrimaryBorderHover | Main contour when hovering. | #85a5ff |
colorText | Text color. | rgba(0,0,0,0.88) |
colorTextDescription | Color descriptions. | rgba(0,0,0,0.45) |
borderRadiusXS | Small rounding. | 2 |
controlHeight | Normal element height. | 32 |
controlHeightLG | Height of large elements. | 40 |
fontFamily | Font 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' |
fontSize | Text size. | 14 |
lineHeight | Row height. | 1.5714285714285714 |
motionDurationMid | Duration of main transitions. | 0.2s |
motionDurationSlow | Duration 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.