Skip to content

[Modal] Fix document scroll behind modal on iOS#48665

Open
olagokemills wants to merge 1 commit into
mui:masterfrom
olagokemills:fix/46791-ios-modal-scroll-lock
Open

[Modal] Fix document scroll behind modal on iOS#48665
olagokemills wants to merge 1 commit into
mui:masterfrom
olagokemills:fix/46791-ios-modal-scroll-lock

Conversation

@olagokemills

@olagokemills olagokemills commented Jun 12, 2026

Copy link
Copy Markdown

Partial fix for #46791

Problem

When an Autocomplete is rendered inside a temporary Drawer, focusing the input on mobile (iOS Safari, Android Chrome) causes the entire document to scroll instead of just the drawer/listbox.

Root cause

A temporary Drawer is a Modal, and ModalManager locks page scrolling by setting overflow: hidden on the document scroll container. iOS Safari does not reliably honor overflow: hidden for touch scrolling, so it only appears locked while nothing overflows. Focusing the Autocomplete opens the on-screen keyboard (shrinking the visual viewport) and the listbox — portaled to document.body — gives the body scrollable overflow that iOS happily scrolls.

Fix

On iOS, additionally pin the document scroll container with position: fixed (the well-known robust scroll-lock technique) and restore the scroll position on unlock so the page doesn't jump to the top.

  • Non-iOS platforms keep the existing overflow: hidden behavior unchanged (no desktop/Android-Chrome regression risk).
  • Custom (non-document) scroll containers are left untouched.
  • iOS detection covers iPadOS 13+, which reports as MacIntel and is distinguished from a real Mac via navigator.maxTouchPoints.

Testing

  • Added unit tests in ModalManager.test.ts covering: body pinned + scroll restored on iPhone UA, iPadOS-as-Mac detection, non-iOS unchanged, disableScrollLock no-op, and non-document container untouched.
  • Manually verified on a physical iPhone (Safari): with the patch, focusing the Autocomplete inside the Drawer no longer scrolls the document, and the scroll position is preserved on close.
ScreenRecording_06-12-2026.16-41-07_1.1.mp4

iOS Safari ignores `overflow: hidden` on the document scroll container for
touch scrolling, so the page scrolls behind a modal once content overflows —
most visibly when focusing an Autocomplete inside a Drawer opens the on-screen
keyboard.

On iOS, additionally pin the document scroll container with `position: fixed`
(the robust scroll-lock technique) and restore the scroll position on unlock to
avoid a jump to the top. Non-iOS platforms and custom (non-document) scroll
containers keep the existing `overflow: hidden` behavior unchanged.

Detection covers iPadOS 13+, which reports as `MacIntel` (distinguished from a
real Mac via `maxTouchPoints`).

Closes mui#46791
@zannager zannager added the scope: modal Changes related to the modal. label Jun 12, 2026
@zannager zannager requested a review from mj12albert June 12, 2026 15:50
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48665--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+485B(+0.09%) 🔺+199B(+0.13%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@mj12albert mj12albert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • The original issue repros for non-iOS as well so if this PR only fixes iOS, then it shouldn't be marked as Fixes #46791
  • It looks like scroll restoration ignores horizontal position

@olagokemills

Copy link
Copy Markdown
Author
  • The original issue repros for non-iOS as well so if this PR only fixes iOS, then it shouldn't be marked as Fixes #46791
  • It looks like scroll restoration ignores horizontal position

Hi there,
So I put a note as partial fix, I could only test on my IOS phone because I am IOS based, Let me see if the issue still exists in an android phone and revert
For your second point, let me investigate this further and revert please

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

Labels

scope: modal Changes related to the modal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants