Skip to content

Commit 6f7765e

Browse files
crisbetojelbourn
authored andcommitted
fix(slide-toggle): run timeout outside the NgZone (#10655)
Moves a timeout, that only has some DOM-related logic, to run outside the `NgZone`.
1 parent 2e3393a commit 6f7765e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/lib/slide-toggle/slide-toggle.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
OnDestroy,
2323
Output,
2424
ViewChild,
25-
ViewEncapsulation
25+
ViewEncapsulation,
26+
NgZone,
2627
} from '@angular/core';
2728
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
2829
import {
@@ -144,7 +145,8 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
144145
private _platform: Platform,
145146
private _focusMonitor: FocusMonitor,
146147
private _changeDetectorRef: ChangeDetectorRef,
147-
@Attribute('tabindex') tabIndex: string) {
148+
@Attribute('tabindex') tabIndex: string,
149+
private _ngZone: NgZone) {
148150

149151
super(elementRef);
150152
this.tabIndex = parseInt(tabIndex) || 0;
@@ -274,9 +276,11 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
274276
this._emitChangeEvent();
275277
}
276278

277-
// The drag should be stopped outside of the current event handler, because otherwise the
278-
// click event will be fired before and will revert the drag change.
279-
setTimeout(() => this._slideRenderer.stopThumbDrag());
279+
// The drag should be stopped outside of the current event handler, otherwise the
280+
// click event will be fired before it and will revert the drag change.
281+
this._ngZone.runOutsideAngular(() => {
282+
setTimeout(() => this._slideRenderer.stopThumbDrag());
283+
});
280284
}
281285
}
282286

0 commit comments

Comments
 (0)