Skip to content

Commit

Permalink
fix(material/slider): aria-valuetext host binding should be onPush co…
Browse files Browse the repository at this point in the history
…mpatible (#29042)

`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.

(cherry picked from commit ce87e55)
  • Loading branch information
atscott authored and andrewseguin committed May 15, 2024
1 parent e26afa9 commit 2f0f576
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/material/slider/slider-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
numberAttribute,
OnDestroy,
Output,
signal,
} from '@angular/core';
import {ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR} from '@angular/forms';
import {Subject} from 'rxjs';
Expand Down Expand Up @@ -69,7 +70,7 @@ export const MAT_SLIDER_RANGE_THUMB_VALUE_ACCESSOR: any = {
host: {
'class': 'mdc-slider__input',
'type': 'range',
'[attr.aria-valuetext]': '_valuetext',
'[attr.aria-valuetext]': '_valuetext()',
'(change)': '_onChange()',
'(input)': '_onInput()',
// TODO(wagnermaciel): Consider using a global event listener instead.
Expand Down Expand Up @@ -211,7 +212,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
_hostElement: HTMLInputElement;

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

/** The radius of a native html slider's knob. */
_knobRadius: number = 8;
Expand Down
4 changes: 2 additions & 2 deletions src/material/slider/slider-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {InjectionToken, ChangeDetectorRef} from '@angular/core';
import {InjectionToken, ChangeDetectorRef, WritableSignal} from '@angular/core';
import {MatRipple, RippleGlobalOptions} from '@angular/material/core';

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ export interface _MatSliderThumb {
_isFocused: boolean;

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

/**
* Indicates whether UI updates should be skipped.
Expand Down
2 changes: 1 addition & 1 deletion src/material/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
const valuetext = this.displayWith(source.value);

this._hasViewInitialized
? (source._valuetext = valuetext)
? source._valuetext.set(valuetext)
: source._hostElement.setAttribute('aria-valuetext', valuetext);

if (this.discrete) {
Expand Down
3 changes: 2 additions & 1 deletion tools/public_api_guard/material/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { QueryList } from '@angular/core';
import { RippleGlobalOptions } from '@angular/material/core';
import { Subject } from 'rxjs';
import { ThemePalette } from '@angular/material/core';
import { WritableSignal } from '@angular/core';

// @public
export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
Expand Down Expand Up @@ -290,7 +291,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
get value(): number;
set value(value: number);
readonly valueChange: EventEmitter<number>;
_valuetext: string;
_valuetext: WritableSignal<string>;
writeValue(value: any): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatSliderThumb, "input[matSliderThumb]", ["matSliderThumb"], { "value": { "alias": "value"; "required": false; }; }, { "valueChange": "valueChange"; "dragStart": "dragStart"; "dragEnd": "dragEnd"; }, never, never, true, never>;
Expand Down

0 comments on commit 2f0f576

Please sign in to comment.