import { Component } from '@angular/core';
import { WrSlider } from 'ngwr/slider';
@Component({ imports: [WrSlider] })
export class MyComponent {}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.
Single value
Bind a number with [(value)] or any Angular form.
<wr-slider [(value)]="volume" min="0" max="100" />Range
Set range to render two thumbs. The bound value is [low, high].
<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.
<wr-slider [(value)]="stepped" min="0" max="100" step="25" />Disabled
<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 withValidators.max. nullis ignored, soreset()leaves the thumb in place. Reset to a number.- In
rangemode, bind[low, high]: a single number puts the high thumb atmax.
API
| Name | Description | Type | Default |
|---|---|---|---|
min | Lower bound. | WrSliderValue | undefined | 0 |
max | Upper bound. | WrSliderValue | undefined | 100 |
step | Step size for keyboard and drag. | number | 1 |
range | Render two thumbs and emit [low, high]. | boolean | false |
disabled | Disable interaction. Bound automatically from the field's disabled state when used with [formField]. | boolean | false |
readonly | Refuse 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. | boolean | false |
showLabel | Render the current value below the track. | boolean | true |
ariaLabel | Accessible name of the thumb — the single one, or the LOWER one in range mode. Falls back to slider.label / slider.lower. | string | null | null |
upperLabel | Accessible name of the upper thumb in range mode. Falls back to slider.upper. | string | null | null |
value | Current value. Bound by [formField], or two-way via [(value)]. Shape follows range: a plain number, or [low, high] in range mode. | WrSliderValue | 0 |
(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.
| Variable | Default | Declared on |
|---|---|---|
--wr-slider-fill | var(--wr-color-primary) | .wr-slider +1 variant override |
--wr-slider-font-family | var(--wr-font-family-base) | .wr-slider |
--wr-slider-label | var(--wr-color-on-surface-muted) | .wr-slider |
--wr-slider-label-font-size | var(--wr-text-sm) | .wr-slider |
--wr-slider-label-line-height | var(--wr-text-sm-leading) | .wr-slider |
--wr-slider-label-margin-top | var(--wr-space-sm) | .wr-slider |
--wr-slider-thumb | var(--wr-color-surface) | .wr-slider |
--wr-slider-thumb-border | var(--wr-color-primary) | .wr-slider +1 variant override |
--wr-slider-thumb-size | 1rem | .wr-slider |
--wr-slider-track | var(--wr-border-base) | .wr-slider |
--wr-slider-track-height | 0.25rem | .wr-slider |
--wr-slider-track-radius | var(--wr-border-radius-pill) | .wr-slider |
Dependencies
| Built on | Form |
|---|---|
| Used by | Schema Form |
See also
Component Number InputA number field with stepper buttons and locale formatting.Component KnobPick a number by turning a dial.Component RatingRate something with stars, in whole or half steps.Component ProgressA bar that shows how far a task has got.Component Form FieldWraps a form control with a label, a hint and its error messages.Guide FormsBind ngwr controls to any Angular form and show their errors.Component FormA plain layout wrapper for a label, a control and its error.