Skip to content

fix: restore focus in FocusScope containment without scrolling the dialog into view#10339

Open
mvanhorn wants to merge 2 commits into
adobe:mainfrom
mvanhorn:fix/10324-focusscope-scroll-restore
Open

fix: restore focus in FocusScope containment without scrolling the dialog into view#10339
mvanhorn wants to merge 2 commits into
adobe:mainfrom
mvanhorn:fix/10324-focusscope-scroll-restore

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Closes #10324

FocusScope containment restored focus with a raw element.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 in FocusScope goes through the scope-aware focusElement helper (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 through focusElement, matching the rest of the file and preserving scroll position.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 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-safe focusSafely path.

🧢 Your Project:

Personal open-source contribution.

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.

Modal jumps to the top when dismissed via underlay press in Chrome/Safari (regression in 1.17.0)

1 participant