Create

Form

Slider

Copy page View as Markdown Open in ChatGPT Open in Claude

An input where the user selects a value from within a given range.

Usage#

app.component.ts
import { WdsSliderComponent } from '@wds/angular/slider';

Examples#

Default#

value between min (0) and max (100), moved by step. Without a visible label, name the slider with label.

Disabled#

disabled dims the slider and excludes it from the keyboard and the form.

Range#

values with two numbers gives two thumbs; the track between them is filled. The attribute takes a list: values="25,75".

Multiple thumbs#

Any number of values gives one thumb per value. Thumbs cannot pass each other.

Vertical#

orientation="vertical" grows upward; give the slider a height (default 10rem).

Controlled#

wds-input fires on every change while dragging, with value and values; wds-change fires once the thumb is released. Here a range from 0 to 1 with step="0.1".

Controlled range0.3 – 0.7

With input#

A slider and a Number Field kept in sync: each updates the other on wds-input. The field shows the value with a percent sign (format-options).

Color temperature#

A gradient above the track and a name for each range. formatValue (a property) sets what screen readers announce (aria-valuetext), e.g. 4500 kelvin, Neutral.

4500K · Neutral

Reference labels#

In a wds-field the wds-field-label names the slider. The labels under the track are decorative (aria-hidden).

Storage

Tick marks#

Tick marks under the track, aligned with the thumb positions: the thumb center moves from 6px to the end minus 6px, so the row has a 6px padding (px-1.5).

Duration (months)

Value tooltip#

A bubble above the thumb shows the value; its position uses the same formula as the thumb.

Rating#

A 1–5 scale with an emoji and a word; formatValue makes screen readers announce the word.

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsSliderField connects the slider to [formField]. A number gives one thumb, an array of numbers one thumb per value; the value updates while dragging. With [formField] Angular does not allow min and max attributes: for a number set them in the schema (min(), max()), a range uses the default 0–100.

Discount20 – 60%Minimum ratingApply

Submitted: —

Template-driven#

WdsSliderValueAccessor makes ngModel work on wds-slider. Inside a <form> each slider needs a name.

Price100 – 300 USDMinimum ratingApply

Submitted: —

Reactive forms#

The same WdsSliderValueAccessor works with formControl and formControlName; an array in the FormControl gives a range.

PriceMinimum ratingApply

Submitted: —

API References#

wds-slider#

Lets the user pick a value, or a range of values, by dragging a thumb along a track. One thumb by default; values with two or more numbers gives a thumb for each (a range).

Attributes

AttributeTypeDefaultDescription
valuenumber0Value of a single thumb. Ignored when values has numbers.
valuesnumber[][]Values of several thumbs, e.g. [25, 75] for a range. The attribute takes a list: values="25,75".
minnumber0Smallest value.
maxnumber100Largest value.
stepnumber1Step between values (arrow keys and dragging). Page Up/Down move by a tenth of the range.
orientationWdsSliderOrientation'horizontal'Direction of the track. A vertical slider grows upward and needs a height (default 10rem).
disabledbooleanfalseDisables the slider and excludes it from form submission.
invalidbooleanfalseError state: red thumb border and aria-invalid.
namestring''Field name in the form; several thumbs submit one entry each.
labelstring''Accessible name when the slider is not in a wds-field with a label.
thumb-labels.thumbLabelsstring[][]Names of the thumbs, added to the label. Default for two thumbs: Minimum, Maximum.

Properties

PropertyDescription
formatValue((value: number, index: number) => string) | nullText read by screen readers for a value (aria-valuetext), e.g. (v) => v + ' GB'.

Events

EventDescription
wds-inputCustomEvent<WdsSliderChangeDetail>Every change while dragging or with the keyboard.
wds-changeCustomEvent<WdsSliderChangeDetail>A committed change: the pointer is released, or a key changed the value.

Methods

MethodDescription
formResetCallback()
formDisabledCallback(disabled: boolean)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

CSS parts (::part)

PartDescription
controlThe area that takes the pointer (track and thumbs).
trackThe track.
rangeThe filled part of the track.
thumbEach thumb (role="slider").

CSS custom properties

PropertyDescription
--wds-slider-track-sizeThickness of the track (default 4px).
--wds-slider-trackColor of the track.
--wds-slider-rangeColor of the filled part.
--wds-slider-thumbColor of the thumbs.

Accessibility#

Screen reader#

Each thumb is a slider with aria-valuenow, aria-valuemin, aria-valuemax and aria-orientation. formatValue adds aria-valuetext, so units or words are read instead of the bare number.

The thumbs are named by label, or by the wds-field-label of a wds-field. With two thumbs the names get Minimum and Maximum (change them with thumb-labels), with more 1 of 3 and so on.

invalid sets aria-invalid, disabled sets aria-disabled and removes the thumbs from the tab order.

The slider takes part in forms: its value is submitted under name, one entry per thumb.

Keyboard support#

KeyFunction
TabMoves focus to the next thumb.
→↑Increases the value by step (in a right-to-left page ← increases).
←↓Decreases the value by step.
Page UpPage DownChanges the value by a tenth of the range.
HomeEndMoves the thumb to the smallest or largest value it can take (up to the neighboring thumb).
Footer