Skip to content

Commit 3931e05

Browse files
crisbetoVivian Hu
authored and
Vivian Hu
committedJan 18, 2019
fix(tooltip): afterHidden stream not being completed (#14620)
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.
1 parent 0b16843 commit 3931e05

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/lib/tooltip/tooltip.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,24 @@ describe('MatTooltip', () => {
453453
} as AnimationEvent);
454454
}));
455455

456+
it('should complete the afterHidden stream when tooltip is destroyed', fakeAsync(() => {
457+
tooltipDirective.show();
458+
fixture.detectChanges();
459+
tick(150);
460+
461+
const spy = jasmine.createSpy('complete spy');
462+
const subscription = tooltipDirective._tooltipInstance!.afterHidden()
463+
.subscribe(undefined, undefined, spy);
464+
465+
tooltipDirective.hide(0);
466+
tick(0);
467+
fixture.detectChanges();
468+
tick(500);
469+
470+
expect(spy).toHaveBeenCalled();
471+
subscription.unsubscribe();
472+
}));
473+
456474
it('should consistently position before and after overlay origin in ltr and rtl dir', () => {
457475
tooltipDirective.position = 'left';
458476
const leftOrigin = tooltipDirective._getOrigin().main;

‎src/lib/tooltip/tooltip.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ export type TooltipVisibility = 'initial' | 'visible' | 'hidden';
528528
'aria-hidden': 'true',
529529
}
530530
})
531-
export class TooltipComponent {
531+
export class TooltipComponent implements OnDestroy {
532532
/** Message to display in the tooltip */
533533
message: string;
534534

@@ -611,6 +611,10 @@ export class TooltipComponent {
611611
return this._visibility === 'visible';
612612
}
613613

614+
ngOnDestroy() {
615+
this._onHide.complete();
616+
}
617+
614618
_animationStart() {
615619
this._closeOnInteraction = false;
616620
}

0 commit comments

Comments
 (0)
Please sign in to comment.