Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-tables-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Avoid error when using Modal Dialog within TreeView
11 changes: 11 additions & 0 deletions src/TreeView/useRovingTabIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export function useRovingTabIndex({
getNextFocusable: (direction, from, event) => {
if (!(from instanceof HTMLElement)) return

// Skip elements within a modal dialog
// This need to be in a try/catch to avoid errors in
// non-supported browsers
try {
if (from.closest('dialog:modal')) {
return
}
} catch {
// Don't return
}

return getNextFocusableElement(from, event) ?? from
},
focusInStrategy: () => {
Expand Down