diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index c117bd17f53..4a3d220ebd4 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -12,7 +12,8 @@ import { Component, DebugElement, ElementRef, - ViewChild + ViewChild, + NgZone, } from '@angular/core'; import {AnimationEvent} from '@angular/animations'; import {By} from '@angular/platform-browser'; @@ -628,6 +629,26 @@ describe('MatTooltip', () => { expect(tooltipDirective._isTooltipVisible()) .toBe(false, 'Expected tooltip hidden when scrolled out of view, after throttle limit'); })); + + it('should execute the `hide` call, after scrolling away, inside the NgZone', fakeAsync(() => { + const inZoneSpy = jasmine.createSpy('in zone spy'); + + tooltipDirective.show(); + fixture.detectChanges(); + tick(0); + + spyOn(tooltipDirective._tooltipInstance!, 'hide').and.callFake(() => { + inZoneSpy(NgZone.isInAngularZone()); + }); + + fixture.componentInstance.scrollDown(); + tick(100); + fixture.detectChanges(); + + expect(inZoneSpy).toHaveBeenCalled(); + expect(inZoneSpy).toHaveBeenCalledWith(true); + })); + }); describe('with OnPush', () => { diff --git a/src/lib/tooltip/tooltip.ts b/src/lib/tooltip/tooltip.ts index d0cc5c1e6f6..7788b03b105 100644 --- a/src/lib/tooltip/tooltip.ts +++ b/src/lib/tooltip/tooltip.ts @@ -307,7 +307,7 @@ export class MatTooltip implements OnDestroy { if (change.scrollableViewProperties.isOverlayClipped && this._tooltipInstance.isVisible()) { // After position changes occur and the overlay is clipped by // a parent scrollable then close the tooltip. - this.hide(0); + this._ngZone.run(() => this.hide(0)); } else { // Otherwise recalculate the origin based on the new position. this._tooltipInstance._setTransformOrigin(change.connectionPair);