-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix focus scope with changing children #2791
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
Conversation
Keep focus scope up to date with changing children and auto focus children
Build successful! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
{showNew && ( | ||
<div role="dialog" onKeyDown={onKeyDown}> | ||
<input /> | ||
<input autoFocus /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoFocus
on this input
means that focus will be maintained within the FocusScope when the children change, however, without the autoFocus
prop, focus will be lost to the document.body
. #2763 has been opened to account for this and keep focus within the FocusScope when contain
is true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, #2763 is the reason we aren't addressing this issue here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, I just have the one question in tests.
|
||
rerender(<Test />); | ||
|
||
expect(document.activeElement).toBe(outside); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care about proving the focus scope doesn't goto .outside
when it isn't focused before we rerender it twice?
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Closes #2415
Keep focus scope up to date with changing children and auto focus children.
The two cases observed are:
This was fixed by using scopeRef.current as pointed out in the issue description because the scope was out of date.
This was fixed by changing when nodeToRestore is set so that it runs before autoFocus takes place.
We are preferring this PR over #2416 right now because it's difficult to review due to the refactor. Not that the refactor is bad, but by breaking this up, we can make sure we know what the fix is, and we can refactor it separately such that no changes to behavior occur.
Thank you @kherock for your hard work on this!
✅ Pull Request Checklist:
📝 Test Instructions:
Test steps (case 1):
Case 2 is covered by the unit test
🧢 Your Project:
RSP