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

Prevent scrolling up when opening a dialog #29832

Merged
merged 2 commits into from
Jan 3, 2019
Merged

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Jan 1, 2019

Changes proposed in this Pull Request

Add a ReactModal__Html--open class to the HTML document that unsets the default overflow-y: scroll; CSS declaration for solving a conflict between that declaration and the ReactModal__Body--open class which is defining a overflow: 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

  • Create a new post with the Classic editor.
  • Add enough content to scroll down.
  • Insert an image at the end of the post.
  • Check that you remain in the same scroll position you were before opening the Media Library.
  • Add a link towards the end of the post (by highlighting some text and clicking on the hyperlink button).
  • Make sure you're still in the same scroll position.
  • Switch to Gutenberg.
  • Insert and image using the Media Library.
  • Check again that the page is not scrolled.

Fixes #16873.
Fixes #27226.
Fixes #29821.

@mmtr mmtr added [Type] Bug [Feature] Post/Page Editor The editor for editing posts and pages. [Pri] High Address as soon as possible after BLOCKER issues [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Feature] Media The media screen in Calypso, general media management, or integration with third party media. [Goal] Gutenberg Working towards full integration with Gutenberg labels Jan 1, 2019
@mmtr mmtr self-assigned this Jan 1, 2019
@matticbot
Copy link
Contributor

@mmtr mmtr requested a review from a team January 1, 2019 14:46
@Copons
Copy link
Contributor

Copons commented Jan 1, 2019

overflow-y: scroll forces displaying the scrollbar even if the content isn’t long enough to scroll.

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. 🤔

@mmtr
Copy link
Member Author

mmtr commented Jan 1, 2019

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 overflow: scroll doesn't affect the size available for the content.

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 overflow-y: scroll and it's causing a regression.

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 overflow: hidden style defined by ReactModal__Body--open, but that will make scrollable the content behind the modal.

@Copons
Copy link
Contributor

Copons commented Jan 1, 2019

We could also keep track of the scroll position before opening the modal, and make sure to scroll back to it after closing it. 🤔

@gwwar
Copy link
Contributor

gwwar commented Jan 1, 2019

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.

@gwwar gwwar added the [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR label Jan 1, 2019
@mmtr
Copy link
Member Author

mmtr commented Jan 2, 2019

I included back the original overflow-y: scroll for the HTML document in d4e248e and created a new ReactModal__Html--open which unsets that CSS and is only applied when opening a dialog, so the change should be less risky now.

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.

Copy link
Contributor

@gwwar gwwar left a 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 🚢

@mmtr mmtr merged commit 947fa04 into master Jan 3, 2019
@matticbot matticbot removed [Status] Needs Design Review Add this when you'd like to get a review / feedback from the Design team on your PR [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 3, 2019
@Copons Copons deleted the fix/modal-scroll-top branch January 3, 2019 13:03
blowery added a commit that referenced this pull request Jan 3, 2019
…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)
@jameskoster
Copy link
Contributor

Did y'all see this? #28737

Seemed like an elegant fix to me.

@mmtr
Copy link
Member Author

mmtr commented Jan 4, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media The media screen in Calypso, general media management, or integration with third party media. [Feature] Post/Page Editor The editor for editing posts and pages. [Goal] Gutenberg Working towards full integration with Gutenberg [Pri] High Address as soon as possible after BLOCKER issues [Type] Bug
Projects
None yet
5 participants