From 5f69f96236cb31d79501c645b3fed59626a5161d Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sun, 23 Dec 2018 21:41:21 +0200 Subject: [PATCH] fix(tooltip): afterHidden stream not being completed Fixes the `afterHidden` stream not being completed, which causes the host tooltip directive to accumulate subscriptions for every time it is opened, until the entire view is destroyed. --- src/lib/tooltip/tooltip.spec.ts | 18 ++++++++++++++++++ src/lib/tooltip/tooltip.ts | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/lib/tooltip/tooltip.spec.ts b/src/lib/tooltip/tooltip.spec.ts index 59f7ac76fa9e..3eeca2442606 100644 --- a/src/lib/tooltip/tooltip.spec.ts +++ b/src/lib/tooltip/tooltip.spec.ts @@ -453,6 +453,24 @@ describe('MatTooltip', () => { } as AnimationEvent); })); + it('should complete the afterHidden stream when tooltip is destroyed', fakeAsync(() => { + tooltipDirective.show(); + fixture.detectChanges(); + tick(150); + + const spy = jasmine.createSpy('complete spy'); + const subscription = tooltipDirective._tooltipInstance!.afterHidden() + .subscribe(undefined, undefined, spy); + + tooltipDirective.hide(0); + tick(0); + fixture.detectChanges(); + tick(500); + + expect(spy).toHaveBeenCalled(); + subscription.unsubscribe(); + })); + it('should consistently position before and after overlay origin in ltr and rtl dir', () => { tooltipDirective.position = 'left'; const leftOrigin = tooltipDirective._getOrigin().main; diff --git a/src/lib/tooltip/tooltip.ts b/src/lib/tooltip/tooltip.ts index 4feca9edf1d5..c431574dc81e 100644 --- a/src/lib/tooltip/tooltip.ts +++ b/src/lib/tooltip/tooltip.ts @@ -528,7 +528,7 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden'; 'aria-hidden': 'true', } }) -export class TooltipComponent { +export class TooltipComponent implements OnDestroy { /** Message to display in the tooltip */ message: string; @@ -611,6 +611,10 @@ export class TooltipComponent { return this._visibility === 'visible'; } + ngOnDestroy() { + this._onHide.complete(); + } + _animationStart() { this._closeOnInteraction = false; }