Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 1c18373

Browse files
committed
Fix use cases in Shadow DOM
Instead of calling document directly we should use getRootNode() to retrieve the right context. This fix will ensure dialogs in shadow root's tabbing behavior is correctly trapped.
1 parent a7e1690 commit 1c18373

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function restrictTabBehavior(event: KeyboardEvent): void {
4949
if (elements.length === 0) return
5050

5151
const movement = event.shiftKey ? -1 : 1
52-
const currentFocus = dialog.contains(document.activeElement) ? document.activeElement : null
52+
const currentFocus = dialog.contains(dialog.getRootNode().activeElement) ? dialog.getRootNode().activeElement : null
5353
let targetIndex = movement === -1 ? -1 : 0
5454

5555
if (currentFocus) {
@@ -99,8 +99,8 @@ function toggle(event: Event): void {
9999
if (!(dialog instanceof DetailsDialogElement)) return
100100

101101
if (details.hasAttribute('open')) {
102-
if (document.activeElement) {
103-
initialized.set(dialog, {details, activeElement: document.activeElement})
102+
if (dialog.getRootNode().activeElement) {
103+
initialized.set(dialog, {details, activeElement: dialog.getRootNode().activeElement})
104104
}
105105

106106
autofocus(dialog)

0 commit comments

Comments
 (0)