Skip to content

Commit b82b091

Browse files
committed
fix(material/select): run viewportRuler change event outside the zone
MatSelect component was listening viewportRuler change event inside the zone. Due to this, a CD cycle was fired after every 'resize' event, event there was nothing to detect changes. It only make sense to run a CD cycle if the mat-select panel is open. Fixes #18546
1 parent a0aee92 commit b82b091

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/material/select/select.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,18 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
568568
}
569569
});
570570

571-
this._viewportRuler.change()
572-
.pipe(takeUntil(this._destroy))
573-
.subscribe(() => {
574-
if (this._panelOpen) {
575-
this._triggerRect = this.trigger.nativeElement.getBoundingClientRect();
576-
this._changeDetectorRef.markForCheck();
577-
}
578-
});
571+
this._ngZone.runOutsideAngular(() =>
572+
this._viewportRuler.change()
573+
.pipe(takeUntil(this._destroy))
574+
.subscribe(() => {
575+
if (this._panelOpen) {
576+
this._ngZone.run(() => {
577+
this._triggerRect = this.trigger.nativeElement.getBoundingClientRect();
578+
this._changeDetectorRef.markForCheck();
579+
})
580+
}
581+
})
582+
);
579583
}
580584

581585
ngAfterContentInit() {

0 commit comments

Comments
 (0)