Skip to content

Commit 7a8af20

Browse files
Remove event memory state in Tooltip when opposite event is fired
1 parent e3de2b0 commit 7a8af20

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/components/Tooltip/Tooltip.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,19 @@ export const Tooltip = ({
8484
searchId.current = Date.now().toString(16) + Math.random().toString(16).slice(2);
8585
setPlaceholder(false);
8686
}, swapDelayTime);
87-
if (placeholderRef.current !== null)
87+
if (placeholderRef.current !== null) {
88+
const eventType = ev.type === "focusin" ? "focusout" : "mouseleave";
8889
(placeholderRef.current as HTMLElement).addEventListener(
89-
ev.type === "focusin" ? "focusout" : "mouseleave",
90-
() => clearTimeout(swapDelay)
90+
eventType,
91+
() => {
92+
if (eventType === "focusout" && eventMemory.current === "afterfocus" ||
93+
eventType === "mouseleave" && eventMemory.current === "afterhover") {
94+
eventMemory.current = null
95+
}
96+
clearTimeout(swapDelay)
97+
}
9198
);
99+
}
92100
};
93101
(placeholderRef.current as HTMLElement).addEventListener("mouseenter", swap);
94102
(placeholderRef.current as HTMLElement).addEventListener("focusin", swap);

0 commit comments

Comments
 (0)