Skip to content

Commit 92ac392

Browse files
gucheenhansl
authored andcommitted
fix(tooltip): remove tooltip component after it's parent destroyed (#1470)
Fixes #1111
1 parent ea6c817 commit 92ac392

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ describe('MdTooltip', () => {
5050
tooltipDirective._handleMouseLeave(null);
5151
expect(overlayContainerElement.textContent).toBe('');
5252
});
53+
54+
it('should be removed after parent destroyed', () => {
55+
tooltipDirective._handleMouseEnter(null);
56+
expect(tooltipDirective.visible).toBeTruthy();
57+
fixture.destroy();
58+
expect(overlayContainerElement.childNodes.length).toBe(0);
59+
expect(overlayContainerElement.textContent).toBe('');
60+
});
5361
});
5462
});
5563

src/lib/tooltip/tooltip.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export class MdTooltip {
6868
this._createOverlay();
6969
}
7070

71+
/**
72+
* Remove overlay after tooltip's parent has been destroyed
73+
*/
74+
ngOnDestroy() {
75+
this.visible = false;
76+
this._overlayRef.dispose();
77+
this._overlayRef = null;
78+
}
79+
7180
/**
7281
* Create the overlay config and position strategy
7382
*/

0 commit comments

Comments
 (0)