Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the page unscrollable while the modal is visible #17247

Merged
merged 5 commits into from
Oct 21, 2024
Merged

Made the page unscrollable while the modal is visible #17247

merged 5 commits into from
Oct 21, 2024

Conversation

oleq
Copy link
Member

@oleq oleq commented Oct 9, 2024

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:

  1. 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.
  2. 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 with absolute 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).
  3. A hybrid that uses overflow: hidden in most cases and position: 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.

Copy link
Contributor

@Dumluregn Dumluregn left a comment

Choose a reason for hiding this comment

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

I found two more potential issues with the current solution:

  • Opening a modal blocks the "pull down" interactions on mobile, i.e. you can't refresh the page this way until you close a modal.
  • If there's no padding on the <body> element reserved for the scrollbar, we get a small page reflow whenever we open or close the modal.

With that in mind, I'd still say this PR brings more value than problems so I'd go with the chosen solution if QA doesn't reveal something critical and business agrees to ignore iOS. The code is alright, just one thing to fix within the manual test itself, and I think it should be possible to write a simple unit test?

@lkszzajac
Copy link

Page is still scrollable on mobile or when using touch simulator in dev tools (see recording)

  • On desktop touch simulator (devtools) scrolling is possible right away
scrolling.via.touch.mov
  • On iOS scroll lock is applied with a delay, and is lifted if the user zooms in/out via pinch-to-zoom (happens automatically when focusing on the text field in the manual test)
  • On Android scrolling inside the dialog is not possible if the document itself is scrollable. Rest of the page is not scroll-locked.
android.scrolling.mp4

@oleq oleq marked this pull request as ready for review October 17, 2024 11:29
@oleq
Copy link
Member Author

oleq commented Oct 17, 2024

I added unit tests in d3cb8e6.

During a summary call with @DawidKossowski and @f1ames we agreed with what @Dumluregn

With that in mind, I'd still say this PR brings more value than problems so I'd go with the chosen solution if QA doesn't reveal something critical and business agrees to ignore iOS.

This is the same approach used by Bootstrap.js or MUI and it should satisfy the majority of our usebase. If this becomes a serious problem for mobile (touch) device users, we'll revisit the solution but until then, we go with the simple overflow: hidden.

@oleq oleq requested a review from Dumluregn October 17, 2024 11:43
@oleq oleq merged commit 926400f into master Oct 21, 2024
10 checks passed
@oleq oleq deleted the ck/17093 branch October 21, 2024 08:17
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.

Disable page scroll when modal is open
3 participants