fix: restore focus in FocusScope containment without scrolling the dialog into view#10339
Open
mvanhorn wants to merge 2 commits into
Open
fix: restore focus in FocusScope containment without scrolling the dialog into view#10339mvanhorn wants to merge 2 commits into
mvanhorn wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10324
FocusScopecontainment restored focus with a rawelement.focus()in two spots (the tab-out restore path and the underlay-triggered re-entry path), which scrolls the focused element into view. Every other restore path inFocusScopegoes through the scope-awarefocusElementhelper (which restores focus without scrolling and is owner-document safe), so these two calls were inconsistent. Dismissing a scrolled dialog via the underlay therefore jumped the page to the top. This routes both containment restore paths throughfocusElement, matching the rest of the file and preserving scroll position.✅ Pull Request Checklist:
📝 Test Instructions:
Render a Dialog/Modal on a page tall enough to scroll, scroll down, open the dialog, then dismiss it by clicking the underlay. Before this change the page jumped back to the top when the dialog closed (focus restoration scrolled the previously focused trigger into view); after this change the scroll position is preserved. The same applies when tabbing out of and back into a contained scope.
Automated:
yarn jest packages/react-aria/test/focus/FocusScope.test.js(59 tests pass), including new assertions that containment focus restoration goes through the scroll-safefocusSafelypath.🧢 Your Project:
Personal open-source contribution.