Skip to content

Commit

Permalink
fix(material-experimental/mdc-progress-bar): run resize observer outs…
Browse files Browse the repository at this point in the history
…ide zone

Runs the `ResizeObserver` from the progress bar outside of the `NgZone` so that it doesn't
trigger change detection.
  • Loading branch information
crisbeto committed Jan 12, 2021
1 parent f5bb3b0 commit d011c7c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/material-experimental/mdc-progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements AfterVie
(this._rootElement.style as any)[styleProperty] = value;
},
getWidth: () => this._rootElement.offsetWidth,
attachResizeObserver: (callback) => {
if ((typeof window !== 'undefined') && window.ResizeObserver) {
const ro = new ResizeObserver(callback);
ro.observe(this._rootElement);
return ro;
attachResizeObserver: callback => {
if (typeof window !== 'undefined' && window.ResizeObserver) {
return this._ngZone.runOutsideAngular(() => {
const resizeObserver = new ResizeObserver(callback);
resizeObserver.observe(this._rootElement);
return resizeObserver;
});
}

return null;
Expand Down

0 comments on commit d011c7c

Please sign in to comment.