Made the page unscrollable while the modal is visible #17247
+185
−1
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.
Suggested merge commit message (convention)
Fix (ui): Made the page unscrollable while the modal is visible. Closes #17093.
Possible strategies
There are two main strategies for freezing the web page scroll available:
overflow: hidden
on<body>
: A very straightforward recipe. It fails in iOS, though. Still, I chose this one because I figured out we can sacrifice the mobile UX for the sake of a simple code and a quicker solution. Besides, Bootstrap.js uses this one and they don't seem to mind at all.position: fixed
on<body>
: Initially, I went with this one because it looked promising but soon I realized it has some drawbacks (also in non-mobile browsers). For instance, it causes page reflows when the body is narrower than the viewport or when the body was positioned withabsolute
in the first place. It requires some extra code (the article shows just basics, there's more to it once you look into it) and feels more complex. I decided it was not worth the hassle (for now).overflow: hidden
in most cases andposition: fixed
for iOS with additional hacks. It's a fairly popular MIT-licensed npm module but I found it overkill for what we need right now.Scope
Currently, only media embed, insert image by URL, and revision history save modals benefit from the change.
Misc
There's a manual test brought in this PR that helps test the behaviors.