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
touch scrolling on iOS will scroll the body BEHIND my modal (with enabled body scroll lock) #200
Comments
I think I may have noticed something like this before - is it related to scrolling momentum? I.e. is it only possible to scroll the body shortly after scrolling to the start/end of your modal? |
For typescript compatibility, see #200
@diachedelic When I remove the momentum from css it's still not working — I noticed that adding For reference, in this scroll-lock library, nested elements do work as expected. But I am not able to tell the difference in the code. |
I created a codesandbox with simplified modal code. https://codesandbox.io/s/priceless-germain-ffrbs EDIT: |
Thanks for the info - if you can reproduce your issue within that code sandbox I will take a closer look. |
@diachedelic Updated the sandbox. It now shows the problem. Thank you in advance. |
I have the exact same problem. When I perform a touch gesture outside the modal the body starts scrolling and I need to click the modals scrollable area again (like I'm sort of activating it) before I'm able to scroll in the modal again. |
Are you able to avoid using |
I need to allow touch move inside my modal since I have scrollable content inside my absolute positioned modal that covers 100% of the screen height and almost the full screen width (to make it behave like a drawer that slides in from the right) On open modal
And then reset body-style attributes on modal close on iOS using the same technique. Hoping for a fix in the body-scroll-lock plugin so that I can remove this hack from my code 🙏 |
But can't you just do |
@diachedelic No because I have nested elements inside the modal that needs to be scrollable -> The
@diachedelic I'm not sure if I understand correctly. I am setting this attribute on the element which needs to be scrollable. function ModalContent({ children }: { children: React.ReactNode }) {
return (
<ModalContentRoot
data-body-scroll-lock-ignore="true"
data-id="modal-content"
>
<ModalContentInner data-id="modal-content-inner">
{children}
</ModalContentInner>
</ModalContentRoot>
);
} I can't use
@diachedelic Then this feature is not really usable? Or is the example in the README wrong? Else we have to rely on a hack like @valleywood described ... Thanks for your support so far. I hope we find a solution. |
I've only ever used |
Using some prop comparison on the react children and according to this assigning a ref to the ModalContent works in the sandbox example. https://codesandbox.io/s/happy-burnell-43lem const contentRef = useRef();
// ...
useBodyScrollLock(contentRef);
// ...
const resolveChildren = ({ children, ref }) => {
const newChildren = React.Children.map(children, (child) => {
if (!React.isValidElement(child)) return;
if (typeof child.props.scrollable === "boolean" && child.props.scrollable) {
return React.cloneElement(child, {
...child.props,
ref
});
}
return child;
});
return newChildren;
};
// ...
const children = resolveChildren({ children: childrenProp, ref: contentRef })
// ...
return (
<div>
{children}
</div>
) I have to check if this solution is also valid on my prod system. The last time I checked something did not work. |
Just providing our experience... We use body-scroll-lock when we open a sidebar drawer menu. Body scrolling is locked successfully on all devices including iOS. Problem: Ultimately, applying this on the target element was the key: In addition, the child of the target (the content of our sidebar drawer) needed the following (however there's more CSS not shown here; sorry unable to put this up atm):
|
As commented here: willmcpo#200 (comment) Other libraries successfully use this strategy on iOS devices, this could be an opt-in to solve many iOS related issues reported here.
As commented here: willmcpo#200 (comment) Other libraries successfully use this strategy on iOS devices, this could be an opt-in to solve many iOS related issues reported here.
They stopped the repairs. I had to do it myself, in the same way, with a new version of typeScript. And fix these problems for everyone to use.
repair log,Refer to the releases page. |
1 similar comment
They stopped the repairs. I had to do it myself, in the same way, with a new version of typeScript. And fix these problems for everyone to use.
repair log,Refer to the releases page. |
System: iOS 13
Description: I am building a modal which opens in a layer above the content and displays e.g. some text. It should lock the body scroll. Scrolling inside the modal should be still possible.
Problem: On iOS 13 there is a problem with nested elements inside the modal. If the scrollable content is at the beginning or the end and cannot be scrolled any further, it is possible to scroll the underlying body element by "scrolling"/touching in the direction without any content so scroll.
I use the provided configuration example from the README. It works as described above that scrolling in nested elements on iOS is possible BUT with the described drawback of scrolling the body behind the modal ...
Is there anything I can do on my end to fix this issue or is it a bug in the library?
The text was updated successfully, but these errors were encountered: