fix(tooltip): not closing when scrolling away (#8688)

Fixes the tooltip not being closed when scrolling away due to the `onPositionChange` being executed outside the `NgZone` after some changes to the `ScrollDispatcher`.
This commit is contained in:
Kristiyan Kostadinov
2017-12-08 18:53:49 +01:00
committed by mmalerba
parent 0d2a419a55
commit d5a2fca336
2 changed files with 23 additions and 2 deletions
+22 -1
View File
@@ -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', () => {
+1 -1
View File
@@ -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);