fix menu bar still sometimes hiding on navigation

This commit is contained in:
bytedream committed 2026-11-02 00:24:43 +01:00
1 parent 191d03c141
commit 9234d29ea3
1 file changed
+8 -6
+8 -6
View File
@@ -58,7 +58,6 @@
let isTouch = $state(false); let isTouch = $state(false);
let isOpen = $state(false); let isOpen = $state(false);
let windowHeight = $state(0); let windowHeight = $state(0);
let pageLoadTimestamp = $state(0);
// lifecycle // lifecycle
$effect(() => { $effect(() => {
@@ -67,8 +66,6 @@
onMount(() => { onMount(() => {
document.addEventListener('astro:page-load', () => { document.addEventListener('astro:page-load', () => {
pageLoadTimestamp = Date.now();
const touchStartListener = () => { const touchStartListener = () => {
isTouch = true; isTouch = true;
}; };
@@ -127,11 +124,16 @@
class:hidden={!(isOpen || showMenuPermanent)} class:hidden={!(isOpen || showMenuPermanent)}
class={isTouch ? 'pb-3' : 'group-hover/menu-bar:block pb-3'} class={isTouch ? 'pb-3' : 'group-hover/menu-bar:block pb-3'}
onmouseenter={() => !isTouch && (isOpen = true)} onmouseenter={() => !isTouch && (isOpen = true)}
onmouseleave={() => { onmouseleave={(event) => {
if (isTouch) return; if (isTouch) return;
// when navigated, the page reload may take a few ms and the menu isn't rendered, which js interprets as an mouse leave // when navigated, the page reload may take a few ms and the menu isn't rendered, which js interprets as an mouse leave
// event. with the 50ms threshold this is mostly fixed, except for maybe slow connections // event
else if (Date.now() - pageLoadTimestamp > 50) isOpen = false; const { left, right, top, bottom } = event.currentTarget.getBoundingClientRect();
const isOverMenu =
event.clientX >= left && event.clientX <= right && event.clientY >= top && event.clientY <= bottom;
isOpen = isOverMenu;
}} }}
role="tooltip" role="tooltip"
> >