Skip to content

Commit d9448d7

Browse files
committed
skip top layer elements in useRovingTabIndex
1 parent 9bcec87 commit d9448d7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/TreeView/useRovingTabIndex.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ export function useRovingTabIndex({
2222
getNextFocusable: (direction, from, event) => {
2323
if (!(from instanceof HTMLElement)) return
2424

25+
// Skip top layer elements
26+
try {
27+
// These need to be separate if conditions as different
28+
// browsers may or may not support them. While we could
29+
// use `:where`, engines like JSDom will still throw.
30+
if (from.closest('dialog[open]')) {
31+
return
32+
}
33+
if (from.closest(':popover-open')) {
34+
return
35+
}
36+
if (from.closest('.:popover-open')) {
37+
return
38+
}
39+
} catch {
40+
// Don't return
41+
}
42+
2543
return getNextFocusableElement(from, event) ?? from
2644
},
2745
focusInStrategy: () => {

0 commit comments

Comments
 (0)