refactor: streamline mobile menu with event delegation

This commit is contained in:
2026-06-06 16:54:11 +02:00
parent f7e7dfd161
commit 4b1b4266d9

View File

@@ -67,11 +67,12 @@ const initMobileMenu = (): void => {
closeMenu(); closeMenu();
}); });
menu.querySelectorAll<HTMLElement>("a, button").forEach((el) => { menu.addEventListener("click", (event) => {
el.addEventListener("click", () => { const target = event.target;
if (!isMobileViewport()) return; if (!(target instanceof Element)) return;
closeMenu(); if (!target.closest("a, button")) return;
}); if (!isMobileViewport()) return;
closeMenu();
}); });
window.addEventListener("resize", () => { window.addEventListener("resize", () => {