Skip to content

fix: RAC modal layout shift when auto-focusing input#10102

Open
nwidynski wants to merge 3 commits into
adobe:mainfrom
nwidynski:fix-ios-modal
Open

fix: RAC modal layout shift when auto-focusing input#10102
nwidynski wants to merge 3 commits into
adobe:mainfrom
nwidynski:fix-ios-modal

Conversation

@nwidynski
Copy link
Copy Markdown
Contributor

@nwidynski nwidynski commented May 25, 2026

Closes

Before vs After

Screen.Recording.2026-05-23.at.11.11.59.PM.mov
Screen.Recording.2026-05-25.at.6.32.24.PM.2.mov

✅ 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:

🧢 Your Project:

Comment on lines +330 to +331
// Hide the modal initially, since an auto-focused input may cause a viewport resize in the next frame.
// If so, delay the reveal by another frame to avoid layout shift when the viewport settles.
Copy link
Copy Markdown
Contributor Author

@nwidynski nwidynski May 25, 2026

Choose a reason for hiding this comment

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

I tried to squeeze this into the hook layer (e.g. useModalOverlay), but that was challenging, due to expectations around a single render pass. This is also pretty opinionated styling, so I ultimately decided to place it in RAC instead.

preventScrollCount++;
if (preventScrollCount === 1) {
if (isIOS()) {
if (isIOS() && isWebKit()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regressed in #1514


if (!opts || !opts.preventScroll) {
scrollIntoViewWhenReady(this, wasKeyboardVisible);
Reflect.defineProperty(HTMLElement.prototype, 'focus', {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as #10041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant