diff --git a/frontend/src/lib/components/menu/Menu.svelte b/frontend/src/lib/components/menu/Menu.svelte index 5739cdc..ee387a0 100644 --- a/frontend/src/lib/components/menu/Menu.svelte +++ b/frontend/src/lib/components/menu/Menu.svelte @@ -5,19 +5,24 @@ let menuElement: HTMLElement; export let onLeave: () => void = () => {}; - function handleFocus(event: FocusEvent) { - if (isOpen && !menuElement.contains(event.target as Node) && menuElement !== event.target) { + function clickOutside(event: MouseEvent) { + if ( + isOpen && + menuElement && + !menuElement.contains(event.target as Node) && + menuElement !== event.target + ) { isOpen = false; onLeave(); } } onMount(() => { - window.addEventListener('focus', handleFocus, true); + window.addEventListener('click', clickOutside, true); }); onDestroy(() => { - window.removeEventListener('focus', handleFocus, true); + window.removeEventListener('click', clickOutside, true); });