From cd63f86efc79710fa60932d9ceebbb2a56d576ec Mon Sep 17 00:00:00 2001 From: Tobias Buschor Date: Tue, 27 Feb 2024 19:29:02 +0100 Subject: [PATCH] Add support for shadow DOM and fix event target bug --- README.md | 6 ++++++ focusgroup.js | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b5ddd4..68bd39c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,12 @@ Focus movement by arrow keys It allows you to focus elements with arrow keys inside a container. +- Works inside shadow dom. +- Use focusgroup="wrap" to focus the first element when the last element is focused and vice versa. +- Use focusgroup="remember" to focus the last focused element when group is focused again. +- Text-Inputs only works for up and down arrow keys. + + See also: https://open-ui.org/components/focusgroup.explainer/ https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/Focusgroup/explainer.md diff --git a/focusgroup.js b/focusgroup.js index e77df03..f9ccca5 100644 --- a/focusgroup.js +++ b/focusgroup.js @@ -72,7 +72,8 @@ function eventTargets(event){ let target = event.target; let container = target.closest('[u1-focusgroup]'); if (!container) { // inside shadow dom - target = event.originalTarget; + target = event.originalTarget; // only for firefox? + if (!target) return {}; container = target.closest('[u1-focusgroup]'); } // TODO? handle slotted elements