Skip to content

Commit 0365141

Browse files
committed
fix(tooltip): should not emit hide event multiple times
1 parent adb029a commit 0365141

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

projects/igniteui-angular/src/lib/directives/tooltip/tooltip-target.directive.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
211211
return;
212212
}
213213

214+
this.target.tooltipTarget = this;
215+
214216
this.checkOutletAndOutsideClick();
215217
const shouldReturn = this.preMouseEnterCheck();
216218
if (shouldReturn) {
@@ -303,6 +305,9 @@ export class IgxTooltipTargetDirective extends IgxToggleActionDirective implemen
303305
this._overlayDefaults.closeOnEscape = true;
304306

305307
this.target.closing.pipe(takeUntil(this.destroy$)).subscribe((event) => {
308+
if (this.target.tooltipTarget !== this) {
309+
return;
310+
}
306311
const hidingArgs = { target: this, tooltip: this.target, cancel: false };
307312
this.tooltipHide.emit(hidingArgs);
308313

projects/igniteui-angular/src/lib/directives/tooltip/tooltip.directive.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,29 @@ describe('IgxTooltip', () => {
575575
expect(targetOne.hideTooltip).not.toHaveBeenCalled();
576576
expect(targetTwo.hideTooltip).toHaveBeenCalledTimes(1);
577577
}));
578+
579+
it('should not emit tooltipHide event multiple times', fakeAsync(() => {
580+
spyOn(targetOne.tooltipHide, 'emit');
581+
spyOn(targetTwo.tooltipHide, 'emit');
582+
583+
hoverElement(buttonOne);
584+
flush();
585+
586+
unhoverElement(buttonOne);
587+
tick(500);
588+
expect(targetOne.tooltipHide.emit).toHaveBeenCalledTimes(1);
589+
expect(targetTwo.tooltipHide.emit).not.toHaveBeenCalled();
590+
flush();
591+
592+
hoverElement(buttonTwo);
593+
flush();
594+
595+
unhoverElement(buttonTwo);
596+
tick(500);
597+
expect(targetOne.tooltipHide.emit).toHaveBeenCalledTimes(1);
598+
expect(targetTwo.tooltipHide.emit).toHaveBeenCalledTimes(1);
599+
flush();
600+
}))
578601
});
579602

580603
describe('Tooltip integration', () => {

0 commit comments

Comments
 (0)