diff --git a/src/lib/components/focus-trap/FocusTrap.svelte b/src/lib/components/focus-trap/FocusTrap.svelte index d93f4dc..c81bc48 100644 --- a/src/lib/components/focus-trap/FocusTrap.svelte +++ b/src/lib/components/focus-trap/FocusTrap.svelte @@ -109,6 +109,10 @@ // Prevent programmatically escaping function handleWindowFocus(event: FocusEvent) { + if (event.target === window.document.body) { + // Workaround for a SvelteKit issue: https://github.com/sveltejs/kit/issues/3501 + return; + } if (!enabled) return; if (containers.size !== 1) return; if (destroying) return; diff --git a/src/lib/components/popover/Popover.svelte b/src/lib/components/popover/Popover.svelte index 05500b2..f539f58 100644 --- a/src/lib/components/popover/Popover.svelte +++ b/src/lib/components/popover/Popover.svelte @@ -137,7 +137,11 @@ onMount(() => registerPopover?.(registerBag)); // Handle focus out - function handleFocus() { + function handleFocus(event: FocusEvent) { + if (event.target === window.document.body) { + // Workaround for a SvelteKit issue: https://github.com/sveltejs/kit/issues/3501 + return; + } if (popoverState !== PopoverStates.Open) return; if (isFocusWithinPopoverGroup()) return; if (!button) return; diff --git a/src/lib/components/popover/PopoverButton.svelte b/src/lib/components/popover/PopoverButton.svelte index 3aaf695..0e009f9 100644 --- a/src/lib/components/popover/PopoverButton.svelte +++ b/src/lib/components/popover/PopoverButton.svelte @@ -42,7 +42,11 @@ let previousActiveElementRef: Element | null = typeof window === "undefined" ? null : document.activeElement; - function handleFocus() { + function handleFocus(event: FocusEvent) { + if (event.target === window.document.body) { + // Workaround for a SvelteKit issue: https://github.com/sveltejs/kit/issues/3501 + return; + } previousActiveElementRef = activeElementRef; activeElementRef = document.activeElement; } diff --git a/src/lib/components/popover/PopoverPanel.svelte b/src/lib/components/popover/PopoverPanel.svelte index 8ff5331..7c1e33d 100644 --- a/src/lib/components/popover/PopoverPanel.svelte +++ b/src/lib/components/popover/PopoverPanel.svelte @@ -99,7 +99,11 @@ } } - function handleFocus() { + function handleFocus(event: FocusEvent) { + if (event.target === window.document.body) { + // Workaround for a SvelteKit issue: https://github.com/sveltejs/kit/issues/3501 + return; + } if (!focus) return; if ($api.popoverState !== PopoverStates.Open) return; if (!$panelStore) return;