-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Prevent scrolling up when opening a dialog #29832
Conversation
The purpose is to prevent the reflow caused by the content obtaining or losing the scrollbar, which happens, for example, when the content length changes, or when you play around with modals. I can confirm that the change in this PR fixes the modal issue, but I honestly don't know how to effectively test for regressions. 🤔 |
Ah, you're right @Copons! Didn't have that in consideration since I'm using the "auto" scrollbars in macOS, so they appear floating over the content and But indeed that reflow is there if I change the setting to always display the scrollbar (and I guess that this is happening always in Windows). I'd say that was the single purpose of I guess we could solve it by doing what Bootstrap does: apply a padding when the modal is opened, so the size available doesn't change. Although this will make the code more complex and I honestly don't like that very much. The alternative is to do what @jameskoster suggested on #16873, remove the |
We could also keep track of the scroll position before opening the modal, and make sure to scroll back to it after closing it. 🤔 |
I think it's probably much less risky for us to adopt a more targeted fix. I don't have any preferences for the approach but will note that JS fixes tend to a bit more finicky and prone to breakage. |
I included back the original This indeed causes the effect described by @Copons: the scrollbar is gone when the modal is open so there is reflow caused by the new size available in the window, but I don't think this is a problem since the change is almost invisible due to the fact that most of the UI changes because the Dialog is covering most of the previous content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mmtr this tests well for me! I think after we verify that we're not using those component refs this is good to 🚢
…sh-2019 * origin/master: Disable select when only one domain exiists (#29873) Tiled galleries: Disable captions (#29776) Prevent scrolling up when opening a dialog (#29832) Gutenberg: Move Shortlinks to production (#29883) Gutenlypso: add convert to blocks dialog (#29790) Gutenberg: Move Related Posts to production blocks (#29650) Analytics: fix ad-tracking issue on signup for non-gdpr countries (#29741) Update mobile phone validation module (used for 2fa) (#29740) Gutenlypso: make sure titles load on second edit (#29877) Site Picker: Change wording of /page and /block-editor to match /post (#29859) Gutenberg: update copy link in page list to be editor aware Gutenberg: use core approach of initialEdits over overridePost Gutenberg: when duplicating a post, override post content Gutenberg: update duplicate url when Gutenlypso is enabled Refactor: Replace use of key-mirror with inline code (#29857) Fixes wrong selected domain name (#29824) Turn off prettier for SASS, use stylelint instead (#29697) Gutenberg: Add copy button to Shortlinks (#29556) add a section name to the body class (#29563)
Did y'all see this? #28737 Seemed like an elegant fix to me. |
Sorry, I wasn't aware about that PR. Although it's the same approach I took at the beginning (a317984) so, as @Copons noted (#29832 (comment)), that didn't prevent the reflow caused by the content obtaining or losing the scrollbar. Which is why I decided to implement a more targeted fix, in order to lose the scrollbar only when the dialog is open. |
Changes proposed in this Pull Request
Add a
ReactModal__Html--open
class to the HTML document that unsets the defaultoverflow-y: scroll;
CSS declaration for solving a conflict between that declaration and theReactModal__Body--open
class which is defining aoverflow: hidden;
for the body.When we scroll in Calypso, we're actually scrolling the body element, so when we disable the scrolling with
overflow: hidden;
, its ancestor, the HTML document, becomes scrollable which by default is scrolled to the top since we have never scrolled that element. Note that although the HTML document is scrollable now, we cannot scroll down when the Dialog is open because the body height is limited to the 100% of the window height.With the
ReactModal__Html--open
we avoid this behavior since the HTML content is now visible and not scrollable. This indeed has side effect: the scrollbar is lost so there is a reflow caused by the new window size available. But I don't think is a big deal, since it's almost inappreciable due to the fact that most of the UI changes because of the dialog.Testing instructions
Fixes #16873.
Fixes #27226.
Fixes #29821.