Slider

Pick a number, or a range of two, by dragging a thumb.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrSlider } from 'ngwr/slider';

@Component({ imports: [WrSlider] })
export class MyComponent {}

Single value

Bind a number with [(value)] or any Angular form.

35
<wr-slider [(value)]="volume" min="0" max="100" />

Range

Set range to render two thumbs. The bound value is [low, high].

200 – 800
<wr-slider [(value)]="priceRange" range min="0" max="1000" step="50" />

Step

Steps count from min: with min 5 and step 10 the thumb stops on 5, 15, 25.

50
<wr-slider [(value)]="stepped" min="0" max="100" step="25" />

Disabled

35
<wr-slider [(value)]="volume" disabled />

Keyboard

Arrows move one step, Shift + arrow and PageUp / PageDown ten steps, Home / End jump to the ends.

Gotchas

  • A value outside [min] / [max] is drawn at the end of the track but stays in the model. Flag it with Validators.max.
  • null is ignored, so reset() leaves the thumb in place. Reset to a number.
  • In range mode, bind [low, high]: a single number puts the high thumb at max.

API

NameDescriptionTypeDefault
minLower bound.WrSliderValue | undefined0
maxUpper bound.WrSliderValue | undefined100
stepStep size for keyboard and drag.number1
rangeRender two thumbs and emit [low, high].booleanfalse
disabledDisable interaction. Bound automatically from the field's disabled state when used with [formField].booleanfalse
readonlyRefuse value changes while the thumbs stay focusable and the value still submits. Bound automatically from the field's readonly state when used with [formField]. The thumbs keep their tab stop and keep announcing their value — arrow keys, Home / End and the pointer simply move nothing — which is the whole difference from disabled, where they would leave the tab order entirely. Mirrored as aria-readonly, which role slider supports.booleanfalse
showLabelRender the current value below the track.booleantrue
ariaLabelAccessible name of the thumb — the single one, or the LOWER one in range mode. Falls back to slider.label / slider.lower.string | nullnull
upperLabelAccessible name of the upper thumb in range mode. Falls back to slider.upper.string | nullnull
valueCurrent value. Bound by [formField], or two-way via [(value)]. Shape follows range: a plain number, or [low, high] in range mode.WrSliderValue0
(touch)Emitted on blur so a bound field can mark itself touched.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/slider's own element.

VariableDefaultDeclared on
--wr-slider-fillvar(--wr-color-primary).wr-slider +1 variant override
--wr-slider-font-familyvar(--wr-font-family-base).wr-slider
--wr-slider-labelvar(--wr-color-on-surface-muted).wr-slider
--wr-slider-label-font-sizevar(--wr-text-sm).wr-slider
--wr-slider-label-line-heightvar(--wr-text-sm-leading).wr-slider
--wr-slider-label-margin-topvar(--wr-space-sm).wr-slider
--wr-slider-thumbvar(--wr-color-surface).wr-slider
--wr-slider-thumb-bordervar(--wr-color-primary).wr-slider +1 variant override
--wr-slider-thumb-size1rem.wr-slider
--wr-slider-trackvar(--wr-border-base).wr-slider
--wr-slider-track-height0.25rem.wr-slider
--wr-slider-track-radiusvar(--wr-border-radius-pill).wr-slider

Dependencies

Built onForm
Used bySchema Form

See also