Skip to content

Commit 5586817

Browse files
committed
fix(material/slider): aria-valuetext host binding should be onPush compatible
`MatSlider` updates `_valuetext` without marking for check. The easiest way to fix these types of issues when values are not part of the public API is to switch them to signals.
1 parent 37958ef commit 5586817

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/material/slider/slider-input.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
numberAttribute,
2121
OnDestroy,
2222
Output,
23+
signal,
2324
} from '@angular/core';
2425
import {ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR} from '@angular/forms';
2526
import {Subject} from 'rxjs';
@@ -69,7 +70,7 @@ export const MAT_SLIDER_RANGE_THUMB_VALUE_ACCESSOR: any = {
6970
host: {
7071
'class': 'mdc-slider__input',
7172
'type': 'range',
72-
'[attr.aria-valuetext]': '_valuetext',
73+
'[attr.aria-valuetext]': '_valuetext()',
7374
'(change)': '_onChange()',
7475
'(input)': '_onInput()',
7576
// TODO(wagnermaciel): Consider using a global event listener instead.
@@ -211,7 +212,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
211212
_hostElement: HTMLInputElement;
212213

213214
/** The aria-valuetext string representation of the input's value. */
214-
_valuetext: string;
215+
_valuetext = signal('');
215216

216217
/** The radius of a native html slider's knob. */
217218
_knobRadius: number = 8;

src/material/slider/slider-interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {InjectionToken, ChangeDetectorRef} from '@angular/core';
9+
import {InjectionToken, ChangeDetectorRef, WritableSignal} from '@angular/core';
1010
import {MatRipple, RippleGlobalOptions} from '@angular/material/core';
1111

1212
/**
@@ -183,7 +183,7 @@ export interface _MatSliderThumb {
183183
_isFocused: boolean;
184184

185185
/** The aria-valuetext string representation of the input's value. */
186-
_valuetext: string;
186+
_valuetext: WritableSignal<string>;
187187

188188
/**
189189
* Indicates whether UI updates should be skipped.

src/material/slider/slider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
726726
const valuetext = this.displayWith(source.value);
727727

728728
this._hasViewInitialized
729-
? (source._valuetext = valuetext)
729+
? source._valuetext.set(valuetext)
730730
: source._hostElement.setAttribute('aria-valuetext', valuetext);
731731

732732
if (this.discrete) {

0 commit comments

Comments
 (0)