fix: tooltip persisting

This commit is contained in:
Maya 2025-11-22 17:41:44 +03:00
parent 0a51188982
commit 7e73c505f8
No known key found for this signature in database
1 changed files with 15 additions and 0 deletions

View File

@ -54,15 +54,30 @@
if (timeout) clearTimeout(timeout); if (timeout) clearTimeout(timeout);
} }
function handleGlobalMouseMove(e: MouseEvent) {
if (!showTooltip || !triggerElement) return;
const triggerRect = triggerElement.getBoundingClientRect();
const isOverTrigger =
e.clientX >= triggerRect.left &&
e.clientX <= triggerRect.right &&
e.clientY >= triggerRect.top &&
e.clientY <= triggerRect.bottom;
if (!isOverTrigger) hide();
}
$effect(() => { $effect(() => {
if (showTooltip && tooltipElement) { if (showTooltip && tooltipElement) {
document.body.appendChild(tooltipElement); document.body.appendChild(tooltipElement);
document.addEventListener("mousemove", handleGlobalMouseMove);
} }
return () => { return () => {
if (tooltipElement && tooltipElement.parentNode === document.body) { if (tooltipElement && tooltipElement.parentNode === document.body) {
document.body.removeChild(tooltipElement); document.body.removeChild(tooltipElement);
} }
document.removeEventListener("mousemove", handleGlobalMouseMove);
}; };
}); });
</script> </script>