Skip to content

Commit

Permalink
fix(tooltip): allow toolip to reopen when closed by detaching overlay (
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and josephperrott committed Nov 10, 2017
1 parent d35436b commit 0719c38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ describe('MatTooltip', () => {
expect(tooltipDirective._tooltipInstance).toBeNull();
}));

it('should be able to re-open a tooltip if it was closed by detaching the overlay',
fakeAsync(() => {
tooltipDirective.show();
tick(0);
expect(tooltipDirective._isTooltipVisible()).toBe(true);
fixture.detectChanges();
tick(500);

tooltipDirective._overlayRef!.detach();
tick(0);
fixture.detectChanges();
expect(tooltipDirective._isTooltipVisible()).toBe(false);
flushMicrotasks();
expect(tooltipDirective._tooltipInstance).toBeNull();

tooltipDirective.show();
tick(0);
expect(tooltipDirective._isTooltipVisible()).toBe(true);
}));

it('should show with delay', fakeAsync(() => {
expect(tooltipDirective._tooltipInstance).toBeUndefined();

Expand Down
8 changes: 4 additions & 4 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ export class MatTooltip implements OnDestroy {

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

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

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

0 comments on commit 0719c38

Please sign in to comment.