body-scroll-lock: Does not work in gatsby projects
In order to lock the scrolling in a gatsby project, the overflow: hidden style property must be set on the root <html style="overflow: hidden;"> element.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 5
- Comments: 21
I had to do this:
@AidanRRR Can you try replacing all instances of
document.bodywithdocument.documentElementinbody-scroll-lockand see if that helps?I was also having this problem, in Gatsby v2.32.10, with body-scroll-lock v3.1.5. My requirement was to lock the scroll when a modal side-navigation “drawer” was open.
The solution in https://github.com/willmcpo/body-scroll-lock/issues/154#issuecomment-612664227 improved the situation, but I also had to dynamically set the
heightstyle of the#gatsby-focus-wrapperdiv, like this: