Workaround tabIndex=-1 added to document body by SvelteKit

This ends up producing a lot of extra focus events that normally would not exist.

Fixes #36
Fixes #39
This commit is contained in:
Ryan Gossiaux
2022-01-21 16:17:16 -08:00
parent ac1f86ac15
commit bc809ef590
4 changed files with 19 additions and 3 deletions

View File

@@ -109,6 +109,10 @@
// Prevent programmatically escaping // Prevent programmatically escaping
function handleWindowFocus(event: FocusEvent) { 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 (!enabled) return;
if (containers.size !== 1) return; if (containers.size !== 1) return;
if (destroying) return; if (destroying) return;

View File

@@ -137,7 +137,11 @@
onMount(() => registerPopover?.(registerBag)); onMount(() => registerPopover?.(registerBag));
// Handle focus out // 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 (popoverState !== PopoverStates.Open) return;
if (isFocusWithinPopoverGroup()) return; if (isFocusWithinPopoverGroup()) return;
if (!button) return; if (!button) return;

View File

@@ -42,7 +42,11 @@
let previousActiveElementRef: Element | null = let previousActiveElementRef: Element | null =
typeof window === "undefined" ? null : document.activeElement; 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; previousActiveElementRef = activeElementRef;
activeElementRef = document.activeElement; activeElementRef = document.activeElement;
} }

View File

@@ -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 (!focus) return;
if ($api.popoverState !== PopoverStates.Open) return; if ($api.popoverState !== PopoverStates.Open) return;
if (!$panelStore) return; if (!$panelStore) return;