mirror of https://github.com/VERT-sh/VERT.git
fix: tooltip persisting
This commit is contained in:
parent
0a51188982
commit
7e73c505f8
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue