Skip to content

Commit

Permalink
fix(tooltip): remove tooltip component after it's parent destroyed (#…
Browse files Browse the repository at this point in the history
…1470)

Fixes #1111
  • Loading branch information
gucheen authored and hansl committed Nov 1, 2016
1 parent ea6c817 commit 92ac392
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ describe('MdTooltip', () => {
tooltipDirective._handleMouseLeave(null);
expect(overlayContainerElement.textContent).toBe('');
});

it('should be removed after parent destroyed', () => {
tooltipDirective._handleMouseEnter(null);
expect(tooltipDirective.visible).toBeTruthy();
fixture.destroy();
expect(overlayContainerElement.childNodes.length).toBe(0);
expect(overlayContainerElement.textContent).toBe('');
});
});
});

Expand Down
9 changes: 9 additions & 0 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export class MdTooltip {
this._createOverlay();
}

/**
* Remove overlay after tooltip's parent has been destroyed
*/
ngOnDestroy() {
this.visible = false;
this._overlayRef.dispose();
this._overlayRef = null;
}

/**
* Create the overlay config and position strategy
*/
Expand Down

0 comments on commit 92ac392

Please sign in to comment.