Skip to content

Commit

Permalink
Merge pull request #2862 from Licen-it/tooltip-fix
Browse files Browse the repository at this point in the history
fix(Tooltip): tooltip will open only if the mouse remains on it and no longer overlap with other tooltips
  • Loading branch information
zvonimirfras authored Apr 19, 2024
2 parents 185f839 + 2130c9c commit 8ff0322
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tooltip/tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked {

@ViewChild("contentWrapper") wrapper: ElementRef<HTMLSpanElement>;

private timeoutId: any; // it should be number, but setTimeout below is matching the NodeJs type instead of the JS type

constructor(
protected elementRef: ElementRef,
protected ngZone: NgZone,
Expand All @@ -89,14 +91,20 @@ export class Tooltip extends PopoverContainer implements AfterContentChecked {

@HostListener("mouseenter", ["$event"])
mouseenter(event) {
setTimeout(() => {
// If a mouseleave is triggered before the tooltip is displayed (before setTimeout of mouseenter completes)
// we trigger the mouseleave only avoiding having to unecessary show the tooltip
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => {
this.handleChange(true, event);
}, this.enterDelayMs);
}

@HostListener("mouseleave", ["$event"])
mouseleave(event) {
setTimeout(() => {
// If a mouseleave is triggered before the tooltip is displayed (before setTimeout of mouseenter completes)
// we trigger the mouseleave only avoiding having to unecessary show the tooltip
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(() => {
this.handleChange(false, event);
}, this.leaveDelayMs);
}
Expand Down

0 comments on commit 8ff0322

Please sign in to comment.