Skip to content

Limit focus retention to when the document body is the activeElement #2182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

robbtraister
Copy link
Contributor

@robbtraister robbtraister commented Jun 1, 2023

Description

DOM nodes may be removed from the tree without having focus. In this case, the mutationObserver is greedy and steals focus that it should not be managing. As described in the adjacent comment, when the focused node is removed, browser focus is assigned to the body. By ensuring the body is the activeElement, we avoid stealing focus when the removed node did not have focus to begin with.

Fixes #2180

DOM nodes may be removed from the tree without having focus. In this
case, the mutationObserver is greedy and steals focus that it
should not be managing. By ensuring the body is the activeElement, we
avoid stealing focus when the removed node did not have focus to begin
with.
Copy link
Contributor

@benoitgrelard benoitgrelard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @robbtraister, thanks for your contribution.
You are right, it was definitely a bit too eager. This is more explicit now and inline with the explanation above.

I have used an early return and removed the now unnecessary conditional too.

@benoitgrelard benoitgrelard merged commit 2ce556d into radix-ui:main Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Popover nested in Dialog does not open
2 participants