Skip to content

fix(cdk/a11y): move focus to root if there are no focusable elements in focus trap - #33654

Merged
crisbeto merged 1 commit into
angular:mainfrom
crisbeto:33622/focus-trap-root
Aug 10, 2026
Merged

crisbeto merged 1 commit into
angular:mainfrom
crisbeto:33622/focus-trap-root

Conversation

@crisbeto

Copy link
Copy Markdown
Member

When focus lands on a focus trap anchor, it looks for focusable elements inside the root element, however if there are none, focus can escape the trap.

These changes include additional logic that will move focus to the root element, if it is focusable, and focus trapping didn't find any focusable descendants.

Fixes #33622.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Aug 10, 2026
@pullapprove
pullapprove Bot requested review from ok7sai and tjshiu August 10, 2026 07:38
…in focus trap

When focus lands on a focus trap anchor, it looks for focusable elements inside the root element, however if there are none, focus can escape the trap.

These changes include additional logic that will move focus to the root element, if it is focusable, and focus trapping didn't find any focusable descendants.

Fixes angular#33622.
@crisbeto
crisbeto force-pushed the 33622/focus-trap-root branch from c0875d6 to 38a0b84 Compare August 10, 2026 12:05
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Aug 10, 2026
@crisbeto
crisbeto merged commit f3e6276 into angular:main Aug 10, 2026
30 of 32 checks passed
@crisbeto

Copy link
Copy Markdown
Member Author

This PR was merged into the repository. The changes were merged into the following branches:

crisbeto added a commit that referenced this pull request Aug 10, 2026
…in focus trap (#33654)

When focus lands on a focus trap anchor, it looks for focusable elements inside the root element, however if there are none, focus can escape the trap.

These changes include additional logic that will move focus to the root element, if it is focusable, and focus trapping didn't find any focusable descendants.

Fixes #33622.

(cherry picked from commit f3e6276)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: cdk/a11y target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Dialog): Dialog loses focus when it doesn't contain any focusable elements

2 participants