diff --git a/components/tooltip/base/nz-tooltip-base.directive.ts b/components/tooltip/base/nz-tooltip-base.directive.ts index 3f5547b08ac..e81c517f74b 100644 --- a/components/tooltip/base/nz-tooltip-base.directive.ts +++ b/components/tooltip/base/nz-tooltip-base.directive.ts @@ -192,6 +192,11 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes ngOnDestroy(): void { this.$destroy.next(); this.$destroy.complete(); + + // Clear toggling timer. Issue #3875 #4317 #4386 + this.hide(); + this.clearTogglingTimer(); + if (this.tooltipRef) { this.tooltipRef.destroy(); } @@ -327,10 +332,9 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes } private delayEnterLeave(isOrigin: boolean, isEnter: boolean, delay: number = -1): void { - if (this.delayTimer) { - clearTimeout(this.delayTimer); - this.delayTimer = undefined; - } else if (delay > 0) { + this.clearTogglingTimer(); + + if (delay > 0) { this.delayTimer = setTimeout(() => { this.delayTimer = undefined; isEnter ? this.show() : this.hide(); @@ -341,4 +345,11 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnInit, OnDes isEnter && isOrigin ? this.show() : this.hide(); } } + + private clearTogglingTimer(): void { + if (this.delayTimer) { + clearTimeout(this.delayTimer); + this.delayTimer = undefined; + } + } }