Problem/Motivation

When a dialog is opened with the "modal" option, all other elements on the page are hypothetically disabled. Even though those other elements are masked, you can still scroll-through the modal to the body, which is awkward and not expected behavior. This can lead to the user being confused after closing a modal as the page has scrolled past where they initiated the modal originally.

Proposed resolution

Disable body-level scrolling when a dialog is opened as a modal, which should address this problem.

Dependency evaluation

tua-body-scroll-lock

  • Maintainership of the package: Project is actively maintained. Last release happened on 18th of July 2023.
  • Security policies of the package: None
  • Code quality: Small UI library, could be maintained by us but since the library needs to chase HEAD on multiple browsers, probably better if that's done by someone else.
  • Other dependencies it would add, if any: none

Release notes snippet

CommentFileSizeAuthor
#155 disable-dialog-scroll-2707291-155.patch1.81 KBeugene.brit
#154 2707291-disable-dialog-scroll-10.2.x.patch1.75 KBedmoreta
#125 2707291-nr-bot.txt90 bytesneeds-review-queue-bot
#120 drupal-dialog-modal-disable-scroll-2707291-120.patch23.42 KBnathan tsai
#115 Andriod_after.png209.82 KButkarsh_33
#115 Android_before.png124.3 KButkarsh_33
#114 IOS_After.png546.44 KButkarsh_33
#114 IOS_Before.png311.25 KButkarsh_33
#109 android_before.png113.34 KBlauriii
#109 android_after.png120.29 KBlauriii
#96 2707291-96.patch8.3 KBeugene.brit
#90 drupal-dialog-modal-disable-scroll-2707291-90.patch4.65 KBbosmaen
#89 2707291-89.patch10 KBmsuthars
#88 2707291-88.patch3.61 KBmsuthars
#86 2707291-86.patch9.25 KBdarvanen
#86 2707291-84-86_interdiff.txt5.63 KBdarvanen
#85 2707291-85.patch9.54 KBdarvanen
#85 2707291-84-85_interdiff.txt5.93 KBdarvanen
#84 2707291-84.patch3.61 KBdarvanen
#84 2707291-80-84_interdiff.txt1.11 KBdarvanen
#74 2707291-74.patch5.94 KBdarvanen
#68 2707291-68.patch6.48 KBmegha_kundar
#67 2707291-67.patch6.61 KBmegha_kundar
#63 2707291-62.patch7.72 KBgauravvvv
#62 interdiff-2707291-61_62.txt5.99 KBgauravvvv
#62 2707291-62.patch8.61 KBgauravvvv
#61 drupal-dialog-modal-disable-scroll-2707291-61.patch5.65 KBdwisnousky
#60 drupal-dialog-modal-disable-scroll-2707291-60.patch5.65 KBdwisnousky
#59 drupal-dialog-modal-disable-scroll-2707291-59.patch5.65 KBdwisnousky
#55 2707291-55.patch5.65 KBranjith_kumar_k_u
#54 2707291-54.patch5.65 KBranjith_kumar_k_u
#53 interdiff_52-53.txt720 bytessuresh prabhu parkala
#53 2707291-53.patch5.65 KBsuresh prabhu parkala
#52 interdiff_2707291_51-52.txt684 bytesankithashetty
#52 2707291-52.patch5.65 KBankithashetty
#51 2707291-49.patch5.71 KBdieterholvoet
#48 interdiff-31-48.txt1.99 KBVidushi Mehta
#48 2707291-48.patch5.02 KBVidushi Mehta
#46 interdiff_31-46.txt1.39 KBkomalk
#46 2707291-46.patch5.38 KBkomalk
#45 interdiff_31-45.txt1.39 KBkomalk
#45 2707291-45.patch5.32 KBkomalk
#31 drupal-dialog-modal-disable-scroll-2707291-31.patch5.28 KBsasanikolic
#30 drupal-dialog-modal-disable-scroll-2707291-30.patch1.58 KBdubcanada
#8 drupal-dialog-modal-disable-scroll-2707291-8.patch5.02 KBsamuel.mortenson
#4 drupal-dialog-modal-disable-scroll-2707291-4.patch1.89 KBsamuel.mortenson
drupal-dialog-modal-disable-body-scroll.patch1.09 KBsamuel.mortenson

Issue fork drupal-2707291

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

samuel.mortenson created an issue. See original summary.

droplet’s picture

Status: Needs review » Needs work

You do need some padding to left (or right) to avoid element shifting. Check bootstrap's modal as example :)

samuel.mortenson’s picture

Thanks @droplet, I'll look into that. I found another bug in my patch where some modals were not calling closeDialog() when closing, which means that the body remained locked even after a modal was closed. You can see this by going into WYSIWYG, changing the text format to "Full HTML", and agreeing to the alert about unsafe markup.

We'll probably need to subscribe to the jQuery UI Dialog events globally (on $(window)) and add a class instead of inline CSS, which would let specific themes override our assumptions about what CSS rules are best for accomplishing this.

samuel.mortenson’s picture

Status: Needs work » Needs review
StatusFileSize
new1.89 KB

Here's a new patch which uses classes instead of inline CSS, and adds a position: fixed rule to body to prevent shifting.

droplet’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs review » Needs work
Issue tags: +CSS

Thanks.

+++ b/core/misc/dialog/dialog.css
@@ -0,0 +1,10 @@
+  position: fixed;

but this trigger `body` scrolls back to the top.

were not calling closeDialog() when closing

Yeah, that's a case. We created our implement in Drupal.dialog and that's too easy to be overridden.

The last submitted patch, 4: drupal-dialog-modal-disable-scroll-2707291-4.patch, failed testing.

samuel.mortenson’s picture

Ah position: fixed was probably not needed then - I understand now that you meant shifting due to the scrollbar disappearing, which Bootstrap handles by adding an arbitrary margin when locking body down. I'm looking into solutions for this now.

Edit: See https://github.com/twbs/bootstrap/issues/9855 for the Bootstrap history of this

samuel.mortenson’s picture

Status: Needs work » Needs review
StatusFileSize
new5.02 KB

This is going to make this issue harder to review, but the new patch prevents scrolling while dialogs are open as modals as well as preventing shifting of body elements due to the scrollbar disappearing. To accomplish this I copied code from https://github.com/twbs/bootstrap/blob/master/js/modal.js and https://davidwalsh.name/detect-scrollbar-width, as Bootstrap has iterated on this logic for awhile now.

I haven't specifically credited these sources in the patch, but am happy to do so if there's a standard comment in core for this. Also, if this added complexity is unwanted in core and people are happy with the body shifting when a modal is open, I can go back to the most simple patch (which is just the overflow: hidden rule).

droplet’s picture

Issue tags: +Usability

Great! I have a quick testing and it works as expected. I will run through the code review soon. and hope somebody able to have a 2nd review also :)

+++ b/core/misc/dialog/dialog.js
@@ -88,12 +104,48 @@
+      // Workaround for missing window.innerWidth in IE8.

We don't support IE8 in D8.

wim leers’s picture

Is it not enough to just cancel the bubbling of scroll events on the dialog?

Bcwald’s picture

Tested in administration theme from dialogs prompted from both WYSIWYG, Views, and fields triggering a dialog. I also tested it on the frontend where the theme is calling the jquery UI Dialog, both worked as intended. I also tested manually closing and 'esc' key closing.

droplet’s picture

@Wim,

I'm afraid not. You can't cancel `document` level scroll event. You can prevent mouseEvent, or touchEvent but can't disable native scrollbar scroll interactive.

You may able to set:

window.scrollTo(0, y);

But it leads to performance & flickering issue I believed.

Alternative way is set `body` to position: absolute; (It's slightly better than position: fixed;.) However, it really works for a pre-designed site only. Not scalable for a framework. eg. Facebook uses that technique. For all other sites, we can't predict how the body & inner elements styling, that would trigger more elements shifting & reflow.

I hope I'm wrong because that would be less code :)

wim leers’s picture

I figured that what I said in #10 would not be possible, because such an obvious, simple solution would of course have been tried first. Just wanted to double-check. Thanks!

nod_’s picture

I don't agree with the issue.

The <dialog> spec doesn't say scrolling should be disabled when a modal is open. And so far neither firefox nor chrome prevent scroll on modal open: http://demo.agektmr.com/dialog/ Since the dialog element was intended are more or less a polyfill for this element, I don't think we should add code for this.

droplet’s picture

Sounds right by reading the SPECS. Anyway, only Chrome supported `dialog`.

So now, the question is "Do we need it for Drupal? and any UX problems by this change?"

It's all about how we code and we think.

A. We can hook it into `dialog.beforecreate` event. In this way, we are changing other elements in the standard way, not the standard dialog itself.
B. We can think that Drupal.dialog is our custom API for dialog than a polyfill, we doing extra scripting before trigger `show` event. We doing that now, dialog.postion.js is an example. ( we also changing the A tag, Submit buttons ..etc ).

** the main point is all our changes should be adaptable to HTML 5.1+ standard in future.

yoroy’s picture

I don't see usability reasons to prevent scrolling in the underlying page.

droplet’s picture

There's one little problem is,

in macbook like devices, that's no visible scrollbar. When you are using touchpad to scroll it in non-scrollable area, the bg will be moved. after closing the modal, you will get a different screen. that may confusing users if their actions inside the modal changed the main screen contents.

By HTML SPEC, dialog scrolling with the page by default .

Bcwald’s picture

I recommend trying the patch, it addresses the scroll bar issue.

Also, I recommend this be added as an option in appearance/settings (global settings) for the site administration to choose if they want to disable scroll or not. In most cases a scrolling background makes no logical sense. If the background page is greyed out, it means it's inaccessible to the user until an action is taken.

yoroy’s picture

The patch works fine, and it does feel more natural to not have scrolling in the background. We do not want to make this a setting, that would just add clutter to the admin interface for a very minor feature that will be hard to explain what it even does. We should come to a decision and act on it. It seems better to me to follow relevant specs than fix a potential usability problem that we don't even know it exists.

Bcwald’s picture

fair point on the checkbox being confusing.

I am having a hard time understanding how it's not a usability problem. The modal applies an overlay over the entire site outside it's contents, making anything behind it unusable. having something scroll behind suggests that actions can be taken on the page outside the modal (like browsing the page, for example) which is not true.

droplet’s picture

Recall for UX feedback before my code reviews and improvement. Thanks

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

brooke_heaton’s picture

This does not patch clean against 8.6.x-dev.

brooke_heaton’s picture

Status: Needs review » Needs work

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dubcanada’s picture

Updated patch for 8.6

sasanikolic’s picture

Here's the updated patch for 8.6 based on @samuel.mortenson changes.

idebr’s picture

Status: Needs work » Needs review

sasanikolic’s picture

Status: Needs review » Needs work

Also to note, I just figured that there is a bug on iOS that makes the body scrollable when the keyboard is opened - in a case when we have a form inside the modal. Somehow, in this case, the fix with overflow: hidden does not apply. I didn't find a proper solution to this yet.

kostyashupenko’s picture

We can't just set "overflow: hidden;" for body tag, because it doesn't work on Safari browser on all devices (iphone, ipad, mac, whatever) -> for such devices "position: fixed;" works good.
So need to think how to implement only one fix, but globally. This is common issue with dialog popups, for now to fix such issues i use additional js that calculates offset between top of page and top of your current window position, then "position: fixed;" for body tag + "top" property with negative value, like

<body class="is-path-frontpage no-overflow" style="top: -578px;">

and

body.no-overflow {
  position: fixed; 
}

But need to be careful when you are under admin user and you have toolbar on the top + default padding-top for body coz this toolbar. So need to find simple solution for all cases.

hj-b’s picture

@sasanikolic thnx! #31 works fine for me against 8.6.2

kostyashupenko’s picture

https://github.com/willmcpo/body-scroll-lock works perfect in all browsers
How we can put it in drupal?

droplet’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

indrajithkb’s picture

Assigned: Unassigned » indrajithkb
Issue tags: -JavaScript +JavaScript
indrajithkb’s picture

These all fixes are done with this module ( https://www.drupal.org/project/modal_page ) except ipad, iphone.
replace this

body.modal-open { 
overflow:hidden; 
}

with

body.modal-open { 
position:fixed; 
}

will fix the issue.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

indrajithkb’s picture

komalk’s picture

Assigned: indrajithkb » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.32 KB
new1.39 KB
komalk’s picture

StatusFileSize
new5.38 KB
new1.39 KB

Status: Needs review » Needs work

The last submitted patch, 46: 2707291-46.patch, failed testing. View results

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new5.02 KB
new1.99 KB

Added a patch which pointed #42.

Status: Needs review » Needs work

The last submitted patch, 48: 2707291-48.patch, failed testing. View results

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

dieterholvoet’s picture

StatusFileSize
new5.71 KB

Re-rolled for 9.2.x.

ankithashetty’s picture

Status: Needs work » Needs review
StatusFileSize
new5.65 KB
new684 bytes

Fixed custom command failures in #51 patch, thanks.

suresh prabhu parkala’s picture

StatusFileSize
new5.65 KB
new720 bytes

Tried to solve the custom command failures.

ranjith_kumar_k_u’s picture

StatusFileSize
new5.65 KB

Tried to fix the custom command failure

ranjith_kumar_k_u’s picture

StatusFileSize
new5.65 KB

another try

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wells’s picture

Confirming patch in #51 (misnamed as #49) applies and still resolves this issue in 9.2.0.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dwisnousky’s picture

Tried to solve the command failures.

dwisnousky’s picture

StatusFileSize
new5.65 KB

Tried solving command failures again

dwisnousky’s picture

StatusFileSize
new5.65 KB
gauravvvv’s picture

StatusFileSize
new8.61 KB
new5.99 KB

Re-rolled patch #61, Attched interdiff for same. Added missing dialog.es6.js file and re compiled. please review

gauravvvv’s picture

StatusFileSize
new7.72 KB

Ignore above patch, it consists yarn update changes.

nod_’s picture

We have a css property that can help because this seems like a lot of code.

https://css-tricks.com/almanac/properties/o/overscroll-behavior/ it doesn't work on safari thought. I would try to go this way and find a safari-specific polyfill.

droplet’s picture

@nod_

both are diff cases I think. CSS one is prevent accidental scroll, this patch is prevent intended scroll (you have no way to scroll the body anymore) also.

both may also be needed.

(and needs mobile touching testings)

droplet’s picture

megha_kundar’s picture

StatusFileSize
new6.61 KB

Fix for jenkins build

megha_kundar’s picture

StatusFileSize
new6.48 KB

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

Re #64

https://css-tricks.com/almanac/properties/o/overscroll-behavior/ it doesn't work on safari thought. I would try to go this way and find a safari-specific polyfill.

Update:
Safari is green now from v16 on!

Shouldn't we at last add a body class, indicating the modal is open and go on with everything else then? I guess that would be helpful in many projects and perhaps we can already agree on that? (This is open since 2016 ...)

berliner’s picture

Adding a body class would be great. That's not intrusive and still allows each site to have a fixed background with minimal effort.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

darvanen’s picture

Status: Needs review » Needs work

#68 since I had to ask about the error it stands to reason that others here probably would have to as well. It's not a very well worded error.

'/var/www/html/core/misc/dialog/dialog.es6.js' is not updated.

effectively means: dialog.js should match the output of yarn build dialog.es6.js

Also, #67 and #68 are missing the new css file.

#64 I've done some testing and sadly overscroll-behavior doesn't completely block the body from scrolling AND it ONLY works if there's a scrollbar inside the modal /sadface

A colleague suggested the new inert attribute but that only blocks clicks, not scrolling.

darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new5.94 KB

Here's a patch against 9.4.x.

I can't provide an interdiff because I used bits and pieces of different prior patches and effectively rewrote it by hand. The .js file is now properly compiled from the .es6.js file.

I found the 'position: fixed' CSS reset the scroll position of the body so I used 'overflow: hidden' instead.

darvanen’s picture

Status: Needs review » Needs work

Scrollbar measurement doesn't work yet.

darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new5.25 KB
new2.31 KB

This should do the trick. I note that it leaves a strip of transparent space in place of the scrollbar. Not sure if that's the best thing to do.

darvanen’s picture

StatusFileSize
new461 bytes
new5.04 KB

Forgot to remove the unnecessary CSS. Third time's the charm?

Status: Needs review » Needs work

The last submitted patch, 77: 2707291-77.patch, failed testing. View results

darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new3.85 KB
new3.15 KB

Really don't need a library just for one line of CSS.

darvanen’s picture

StatusFileSize
new2.54 KB
new3.61 KB

Argh, apologies for the spam, found another issue with the patch. Overflow style should only be applied for modals, not all dialogs.

Status: Needs review » Needs work

The last submitted patch, 80: 2707291-80.patch, failed testing. View results

darvanen’s picture

Manual testing of the first failure shows it's working fine. I think there may be a quirk in how the test driver looks for visible content?

darvanen’s picture

Version: 10.1.x-dev » 9.4.x-dev
Category: Feature request » Bug report
Issue tags: +Bug Smash Initiative

Asked around in #bugsmash on Slack and @ambermatz and @mstrelan both agree with me that this is a usability bug, not just a feature request.

darvanen’s picture

StatusFileSize
new1.11 KB
new3.61 KB

Discovered a small issue with removing the body padding style.

darvanen’s picture

StatusFileSize
new5.93 KB
new9.54 KB

Thanks to @mstrelan for the chat on slack where they pointed out that getText() is intended only for visible text as per the documentation

java.lang.String getText()
Get the visible (i.e. not hidden by CSS) text of this element, including sub-elements.

This means that it should not be used for the live-announce system which is where these tests are failing.

For illustration purposes I'm uploading a patch which passes those tests locally.

I assume this is a big enough scope creep to warrant a separate issue so I'm going to go make one now and then postpone this issue on it.

darvanen’s picture

Related issues: +#3087213: Create a test trait for assertAnnounceContains and assertAnnounceNotContains
StatusFileSize
new5.63 KB
new9.25 KB

Hahaha, of course. As soon as I finish with that comment I discover via #3087213: Create a test trait for assertAnnounceContains and assertAnnounceNotContains that there's already a standard for assertAnnounceContains.

New patch uploaded which alters the failing tests to use that instead.

I'm no longer sure this needs a separate issue for the test updates.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

msuthars’s picture

StatusFileSize
new3.61 KB

#86 patch re-rolled for core 9.5.x.

msuthars’s picture

StatusFileSize
new10 KB

Patch #86 re-rolled again for core 9.5.x, forgot to add tests.

bosmaen’s picture

StatusFileSize
new4.65 KB

For 9.5.x going off what #51 created.

bosmaen’s picture

matroskeen’s picture

What was the reason to create a patch in #90? It doesn't have tests, and more importantly - it's not working because if this line:

// Add body classes to indicate that the dialog is open.
body.addClass('drupal-dialog-open');

body should be prefixed with $

I'm hiding the patch anyway because it should not be applied.

robin.houtevelts’s picture

Others seeing this: Dont apply #90
As said by Matroskeen: It breaks dialogs.

Uncaught ReferenceError: body is not defined

gauravvvv’s picture

Updating attributions

bnjmnm’s picture

Issue tags: +Field UX

Tagging field UX as those efforts will likely increase the use of dialogs.

eugene.brit’s picture

StatusFileSize
new8.3 KB

Re-roll #89 for 10.0.x

lauriii’s picture

Status: Needs work » Needs review

Utkarsh_33 made their first commit to this issue’s fork.

utkarsh_33’s picture

Version: 9.5.x-dev » 11.x-dev

Status: Needs review » Needs work

The last submitted patch, 96: 2707291-96.patch, failed testing. View results

narendraR made their first commit to this issue’s fork.

narendrar’s picture

I was not able to test this MR until I removed if condition from
`
if (scrollBarWidth > 0) {
document.body.style.paddingRight = `${bodyPad + scrollBarWidth}px`;
}
`
as I was getting scrollBarWidth == 0.

hooroomoo made their first commit to this issue’s fork.

hooroomoo’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Hiding the patches as they aren't relevant anymore

Testing MR 4131
Confirmed the issue by opening up Media Library in the ckeditor and placing my cursor outside the modal and I can scroll
Applying the MR and that issue has gone away.

Seems a few committers have been on this thread but to me seems the changes for assertAnnounceContains were out of scope of this issue.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new120.29 KB
new113.34 KB

There's a regression with Android Chrome as a result of this change. Added screenshots for before and after.

lauriii’s picture

It looks like the module mentioned in #66 is using https://github.com/willmcpo/body-scroll-lock. Maybe we should consider adopting that too?

Edit: Looks like the that library is abandoned. We could consider adopting one of the forks, e.g. https://github.com/tuax/tua-body-scroll-lock or https://github.com/rick-liruixin/body-scroll-lock-upgrade. It seems a fairly small UI library so even if we had to fork it ourself, wouldn't probably be the worst thing.

utkarsh_33’s picture

utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs change record

Now that we are adding a new vendor asset. Think the issue summary could be updated to include that. Also do we need a change record that a new asset is being added?

utkarsh_33’s picture

StatusFileSize
new311.25 KB
new546.44 KB

Tested it for IOS in safari browser.The body level scrolling is locked for IOS.Attached the screenshots which i tested.

utkarsh_33’s picture

StatusFileSize
new124.3 KB
new209.82 KB

Tested it for android.The body level scrolling is locked for android also.Attached the screenshots which i tested.

utkarsh_33’s picture

Issue summary: View changes

Updated issue summary.

utkarsh_33’s picture

Issue summary: View changes
utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update

For change record.

nathan tsai’s picture

Latest diff:

[Ah shucks, the latest diff doesn't apply to Drupal 10 :(]

nathan tsai’s picture

lauriii’s picture

Discussed with @catch on Slack to confirm that from release management standpoint it would be acceptable to use one of the libraries proposed in #110. Since we are not 100% confident about any of the libraries, @catch recommended that we add the library as an asset of the dialog library to reduce the risk of someone using this as an API.

Discussed with @bnjmnm to get his take on which of the libraries we should use from #110, and he recommended that we compare the more-current but less-used https://github.com/rick-liruixin/body-scroll-lock-upgrade against the original library and verify the changes are fine. This would help rule out issues that might have been already-discovered if it had more usage. Also, since the library doesn't break BC, it might provide us an option of going to one of the other forks if this one doesn't work out well.

hooroomoo’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Looked at https://github.com/rick-liruixin/body-scroll-lock-upgrade with @lauriii and concluded that we currently can't use that library since we can't import from esm files in Drupal, there is no UMD release provided, and bundling it ourselves to make it compatible feels like overkill for this issue. I filed an issue requesting a UMD file.

But for now we can probably just move forward with the original MR4131 that uses tua-body-scroll-lock.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

lauriii’s picture

Status: Needs work » Needs review

I don't know what is going on with the MR's since neither of them seems to have the right commits 🤔. I guess we need to start from the patch in #120 again?

smustgrave’s picture

Status: Needs review » Needs work

Could the changes from the 2 MRs be documented to be added to the patch?

lauriii’s picture

+++ b/core/core.libraries.yml
@@ -875,6 +876,16 @@ tabbable:
+tua-body-scroll-lock:
...
+    assets/vendor/tua-body-scroll-lock/tua-bsl.umd.js: { minified: true }

One of the remaining feedback here is that we need to move the asset from its own library to be loaded directly as part of drupal.dialog library.

hooroomoo’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

#130 appears to be addressed

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted feedback on the MR

utkarsh_33’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All threads appear to be addressed so think this can be moved back to RTBC.

lauriii’s picture

Issue summary: View changes

Adding dependency evaluation.

lauriii’s picture

Tested the behavior with @penyaskito on iOS and Android to confirm that the latest solution works with both platforms.

lauriii’s picture

Tested the behavior on the latest version with @penyaskito on iOS and Android 👍

  • longwave committed 6cfd0670 on 11.x
    Issue #2707291 by Utkarsh_33, lauriii, darvanen, samuel.mortenson,...
longwave’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +ddd2023

Great to finally solve this. Discussed additional testing with @lauriii at Drupal Dev Days but due to the fact this mostly affects mobile browsers only and specifically Safari, that adding JS testing is somewhat pointless for Chrome - we should revisit this if one day we have explicit mobile tests via Browserstack or similar.

Also discussed the copy-paste of assertAnnounceContains() which we should consider moving to WebAssert in a followup.

Committed and pushed 6cfd0670af to 11.x. Thanks!

dieterholvoet’s picture

Isn't this being backported to 10.1?

penyaskito’s picture

As this requires a new dependency, those are usually only added to minor releases, not patch releases. See https://www.drupal.org/about/core/policies/core-change-policies/allowed-...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

Published the change record. Should a usage example be added?

larowlan’s picture

Status: Closed (fixed) » Needs review

Sorry to be late to the issue here, but did we consider using overflow:clip here

We should be able to use the has selector and that to achieve this with a few lines of CSS

larowlan’s picture

I made https://codepen.io/larowlan/pen/QWzMzgo for a demo - works in Chrome but unfortunately Firefox doesn't support :has yet.

I wonder if we should mark this library as internal/deprecated knowing that when Firefox supports has we can drop it?

roromedia’s picture

In response to the previous comment from @larowlan, I conducted a preliminary test on a desktop setup (no mobile testing yet), utilizing Gin as the backend theme. I integrated the following CSS adjustments:

body:has(.ui-dialog) {
  overflow: clip;
}
body  .ui-front {
  height: 90vh !important;
  min-height: 90vh;
}
 body .ui-dialog {
  overflow-y: scroll;
  overflow-x: hidden;
  height:98vh !important;
  margin-top: 1vh;
  margin-bottom: 1vh;
  display: flex;
  flex-direction: column;
}

The results were perfect. Both the Media modals and the Layout Paragraph Modal functioned seamlessly. Kudos for these insights!

smustgrave’s picture

Assigned: Unassigned » larowlan
Status: Needs review » Reviewed & tested by the community

Since this wasn't reverted should anything be done @larowlan?

longwave’s picture

I think this could be explored in a followup but we should leave the original issue as fixed.

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

edmoreta’s picture

StatusFileSize
new1.75 KB

Patch for 10.2.x branch

eugene.brit’s picture

StatusFileSize
new1.81 KB

re-roll for 10.3.x

liquidcms’s picture

This seems to be "fixed" in 10.4. Can someone suggest how to revert this back to the way it was in D9 (despite everyone saying no one would want to scroll the background when a modal is open, my client is pretty annoyed this is now broken).

bnjmnm’s picture

@liquidcms A true revert would either be a patch or overriding the two JS files updated but the quickest way to go back to the earlier behavior is probably to disable the scroll lock immediately after it is activated.

in a custom module add a jQuery event listener on 'dialog:aftercreate', which is triggered immediately after the scroll lock is added.

In the callback, run the same code that is run when the modal dialog closes

const $scroll = $element.find('.scroll');
    if ($scroll.length) {
      bodyScrollLock.unlock($scroll.get(0));
    }

This might not be it line-for-line, I didn't actually try it, but this approach should work - fortunately an event is dispatched right after the scroll lock so it's quite available for disabling.

ac’s picture

(function ($, Drupal, bodyScrollLock) {
  'use strict';
  Drupal.behaviors.foo = {
    attach: function(context, settings) {
      $(window).on('dialog:aftercreate', function(event, dialog, $element, settings) {
        bodyScrollLock.unlock($element.get(0));
      });
    }
  }
})(jQuery, Drupal, bodyScrollLock);

You can disable it like this. In our experience having this enabled has created major issues in IOS with users unable to scroll dialogs that are larger than the viewport. It might be specific to our use case and we have not look at it beyond this yet.