mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
mmalerba
parent
0d2a419a55
commit
d5a2fca336
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user