it is possible to scroll the body while a dialog is opened (iOS 11)
Bug
What is the expected behavior?
By default, it should not be possible to scroll the body while a dialog is opened.
What is the current behavior?
With an iPhone 8, iOS 11 the body can be scrolled, although a dialog is open. I cannot reproduce this on Mac OS X Chrome/Safari or Android Chrome (other browsers not tested).
What are the steps to reproduce?
Open https://material.angular.io/components/dialog/overview with Safari on a iPhone 8, iOS 11 and click "Pick one" in the example. After the dialog was opened, try to scroll anywhere.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
iOS 11.0.3, Safari
This is not iOS 11-specific; the same happens on iOS 9 & 10.
This is not specific to iOS, this happens on all browsers for all devices, as far as I can tell. Would be awesome if we could have a tag like "cdkPopup" or "cdkDialog" that we could slap on anything that would disable overflow scrolling in the html body whenever the tagged element is rendered on screen.
This is not specific to iOS
I don't think that's true. On Android Chrome scroll is blocked as intended.
It's happening for us on Windows Chrome, Firefox, Edge, and MacOS Chome, Safari, and Firefox
I'm not sure what you're seeing. Me & my colleagues have scroll blocked correctly in Chrome for macOS.
Unfortunately, "works on my machine" doesn't fix the issue at hand. We're on the latest version of all packages and dependencies, if it helps.
I realize that but an issue needs to be reproducible to be able to act on it. Also, it's not just "on my machine" but also on machines of other people that I asked to verify that behavior.
Are you saying that opening: https://material.angular.io/components/dialog/overview and clicking "Pick one" shows the dialog and the overlay which darkens the outside content and yet you can still scroll the whole site?
@mgol this is working as intended. The scroll strategy of dialogs is to not scroll when one is open. You can see this from here: https://github.com/angular/material2/blob/master/src/lib/dialog/dialog.ts#L51
The ScrollStrategy is BlockScrollStrategy which means no scrolling it blocks it from happening.
The reason for this is you can't interact with the background when a dialog is open so scrolling shouldn't happen in either.
To me this is working as intended.
@mgol, I can confirm there is some inconsistency in scrolling.
All test are done on the page: https://material.angular.io/components/dialog/overview by opening modal on clicking Pick one.
Also I observed the behavior of the sidebar is different across browsers, thats probably a different issue.
Windows 10:
- Chrome 62:
- Page scrolling is blocked while modal is opened.
- Sidenav has a scrollbar.
- Table of contents is sticky.
- Opera 49:
- Page scrolling is blocked while modal is opened.
- Sidenav has a scrollbar.
- Table of contents is sticky.
- Internet Exporer 11:
- Page scrolling is blocked while modal is opened.
- Sidenav has a scrollbar.
- Table of contents isn't sticky.
- Edge 16:
- Page scrolling is blocked while modal is opened.
- Sidenav hasn't a scrollbar, sidenav is scrolled with the entire page.
- Table of contents isn't sticky.
- Firefox 57:
- Page scrolling isn't blocked while modal is opened.
- Sidenav hasn't a scrollbar, sidenav is scrolled with the entire page.
- Table of contents isn't sticky.
Android 8.1(Developer preview 2) [nexus 6p]
- Chrome 62:
- Page scrolling isn't blocked while modal is opened.
- Sidenav scrolls the entire page when reaching the bottom of the sidenav.
- Page is scrollable on backdrop while sidenav is opened.
- Opera 44:
- Page scrolling is blocked while modal is opened.
- Sidenav scrolls the entire page when reaching the bottom of the sidenav.
- Page is scrollable on backdrop while sidenav is opened.
- Firefox 57:
- Page scrolling isn't blocked while modal is opened.
- Sidenav scrolls the entire page when reaching the bottom of the sidenav.
- Page is scrollable on backdrop while sidenav is opened.
iOS 10.3.3 [iPhone 5c]
- Safari 10:
- Page scrolling is blocked while modal is opened.
- Sidenav scrolls the entire page when reaching the bottom of the sidenav (wait for animation to stop).
- Page is scrollable on backdrop while sidenav is opened.
- Chrome 62
- Page scrolling is blocked while modal is opened.
- Sidenav scrolls the entire page when reaching the bottom of the sidenav (wait for animation to stop).
- Page is scrollable on backdrop while sidenav is opened.
I can confirm that! It neither blocks scrolling in our app nor on https://material.angular.io/components/dialog/overview.
Tested on Safari on iPhone 6s, iOS 12.1.4 Safari on iPad ?, iOS 12.0.1 Firefox 65.0.1 on Linux (scrolling possible via mouse wheel)
btw. it happens in any Angular Material version form 5 to 7.
Is there any workaround for this?
Same issue here. In particular it happens when you refresh the page the dialog will automatically pop-up on. So inside the ngOnInit() we open the dialog. When navigating from another page, this doesn't seem to be a problem. It can also be reproduced in Chrome.
This seems to be a good workaround: https://css-tricks.com/prevent-page-scrolling-when-a-modal-is-open/ (the javascript part).
Inside the component that I use as parameter inside dialog.open(), I have the following code:
public ngOnInit(): void {
document.body.style.position = 'fixed';
document.body.style.top = `-${window.scrollY}px`;
}
public ngOnDestroy(): void {
const scrollY = document.body.style.top;
document.body.style.position = '';
document.body.style.top = '';
window.scrollTo(0, parseInt(scrollY || '0', 10) * -1);
}
Hello,
Thank you for reaching out. When I navigate to Open https://material.angular.io/components/dialog/overview and click "Pick one", I am not able to scroll the body.
I believe this issue has already been fixed. If you still see incorrect behavior, feel free to reopen this issue or file a new issue report.
- iOS 16.6.1
- iPhone 13 mini
- https://material.angular.io/components/dialog/overview
Best regards,
Zach
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.