Skip to content

Commit 0719c38

Browse files
crisbetojosephperrott
authored andcommitted
fix(tooltip): allow toolip to reopen when closed by detaching overlay (#8232)
1 parent d35436b commit 0719c38

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ describe('MatTooltip', () => {
113113
expect(tooltipDirective._tooltipInstance).toBeNull();
114114
}));
115115

116+
it('should be able to re-open a tooltip if it was closed by detaching the overlay',
117+
fakeAsync(() => {
118+
tooltipDirective.show();
119+
tick(0);
120+
expect(tooltipDirective._isTooltipVisible()).toBe(true);
121+
fixture.detectChanges();
122+
tick(500);
123+
124+
tooltipDirective._overlayRef!.detach();
125+
tick(0);
126+
fixture.detectChanges();
127+
expect(tooltipDirective._isTooltipVisible()).toBe(false);
128+
flushMicrotasks();
129+
expect(tooltipDirective._tooltipInstance).toBeNull();
130+
131+
tooltipDirective.show();
132+
tick(0);
133+
expect(tooltipDirective._isTooltipVisible()).toBe(true);
134+
}));
135+
116136
it('should show with delay', fakeAsync(() => {
117137
expect(tooltipDirective._tooltipInstance).toBeUndefined();
118138

src/lib/tooltip/tooltip.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ export class MatTooltip implements OnDestroy {
255255

256256
/** Create the tooltip to display */
257257
private _createTooltip(): void {
258-
let overlayRef = this._createOverlay();
259-
let portal = new ComponentPortal(TooltipComponent, this._viewContainerRef);
258+
const overlayRef = this._createOverlay();
259+
const portal = new ComponentPortal(TooltipComponent, this._viewContainerRef);
260260

261261
this._tooltipInstance = overlayRef.attach(portal).instance;
262262

263-
// Dispose the overlay when finished the shown tooltip.
264-
this._tooltipInstance!.afterHidden().subscribe(() => {
263+
// Dispose of the tooltip when the overlay is detached.
264+
overlayRef.detachments().subscribe(() => {
265265
// Check first if the tooltip has already been removed through this components destroy.
266266
if (this._tooltipInstance) {
267267
this._disposeTooltip();

0 commit comments

Comments
 (0)