Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/utilities/src/a11y/TrapFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class TrapFocus {
// Focus stayed inside the wrapper, no need to refocus
if (this.#root.contains(currentActiveElement)) return;

// Focus was intentionally moved to another component (e.g. a portal opened from inside the trap).
// Only refocus when focus was dropped (fell back to body), not when another component took it.
if (document.activeElement && document.activeElement !== document.body) return;

const focusable = getFocusableElements(this.#root, {
additionalElement: includeTrigger ? trigger : undefined,
});
Expand Down