Skip to content

fix(material/slider): fix cd for sliders w/ form controls #27250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/material/slider/slider-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
this._updateThumbUIByValue();
this._slider._onValueChange(this);
this._cdr.detectChanges();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, so it calls detectChanges here! Does it effectively mean CD runs twice, if the value is set during change detection?

looks like other material input components (matInput directive, mat-radio) do not do this.

I suspect it might be a source of subtle issues down the line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I remember, this call to detectChanges is needed in order to avoid changed after checked errors. This function is only called when the slider value is set manually so the additional round of change detection shouldn't be too expensive. From what I understand about other components, they don't do this because they do not use the underlying input as the source of truth and therefore don't need to handle changed after checked errors

this._slider._cdr.markForCheck();
}
/** Event emitted when the `value` is changed. */
@Output() readonly valueChange: EventEmitter<number> = new EventEmitter<number>();
Expand Down
4 changes: 3 additions & 1 deletion 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} from '@angular/core';
import {InjectionToken, ChangeDetectorRef} from '@angular/core';
import {MatRipple, RippleGlobalOptions} from '@angular/material/core';

/**
Expand Down Expand Up @@ -153,6 +153,8 @@ export interface _MatSlider {

/** Used to set the transition duration for thumb and track animations. */
_setTransition: (withAnimation: boolean) => void;

_cdr: ChangeDetectorRef;
}

export interface _MatSliderThumb {
Expand Down