Comments (5)
from body-scroll-lock.
Hey, thanks @willmcpo for the quick response!
Elaborating on my scenario
So I did some more digging into this and there seems to have been more to it then I thought. So the problem starts already when I call disableBodyScroll
as this will set the restore values that you mention. In my case these saved restore values are incorrect due to material-ui/Dialog setting overflow: hidden
to document.body
before disableBodyScroll
is fired, and therefore calling enableBodyScroll
does not work. Don't really know how to go about this issue but I somehow expected that enableBodyScroll
would enable body scrolling regardless of when I might have called disableBodyScroll
.
The issue
Incorrect restore values being saved and no way to correct them.
Suggestion
What if the library exposed a function to either update the previousBody...
vars or one that set some similar initialBody...
vars to be used instead if defined?
Demo
I recreated a condensed example of the issue in this CodeSandbox where I use your library within the ScrollLock
component.
https://codesandbox.io/s/50nkpljo9l
from body-scroll-lock.
Since this is a compatibility issue with handling of overflow: hidden
on document.body
, another solution would be to let lib users opt in/out of the css/js solutions of scroll canceling.
from body-scroll-lock.
I see that you already forward the options
object to the function setOverflowHidden
. What if this function was updated to something like below to allow control of the restore values.
const setOverflowHidden = (options = {}) => {
const {
reserveScrollBarGap,
restoreBodyPaddingRight: optionsBPR,
restoreBodyOverflowSetting: optionsBOS,
} = options
// Setting overflow on body/documentElement synchronously in Desktop Safari slows down
// the responsiveness for some reason. Setting within a setTimeout fixes this.
setTimeout(() => {
// If previousBodyPaddingRight is already set, don't set it again.
if (previousBodyPaddingRight === undefined) {
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth
if (reserveScrollBarGap && scrollBarGap > 0) {
// type-check against undefined to allow falsy values
previousBodyPaddingRight = optionsBPR !== undefined
? optionsBPR
: document.body.style.paddingRight
document.body.style.paddingRight = `${scrollBarGap}px`
}
}
// If previousBodyOverflowSetting is already set, don't set it again.
if (previousBodyOverflowSetting === undefined) {
// type-check against undefined to allow falsy values
previousBodyOverflowSetting = optionsBOS !== undefined
? optionsBOS
: document.body.style.overflow
document.body.style.overflow = 'hidden'
}
})
}
from body-scroll-lock.
from a quick glimpse, seems ok and intuitive.
would you mind putting that in a PR ? =) 👍
from body-scroll-lock.
Related Issues (20)
- Header Logo doesn't change to stacked version on Mobile
- Scroll bar width calculated incorrectly HOT 3
- Enabling and clearing body scroll don't work on iOS 15.1
- The scroll lock does not work if you swipe with two fingers at the same time
- Still able to scroll HOT 5
- Doesn't seem to lock HTML tag scrolling HOT 2
- iOS Devices: "restorePositionSetting" can run before "setPositionFixed"
- Inset of iOS devices is scrollable on modals HOT 1
- The content is twitching 15px from the right on MacOS Safari HOT 3
- Black bar at bottom when safari toolbar is hidden on iOS 15
- The package is not tree-shakeable due to side-effects
- Is this package dead/abandoned? HOT 17
- Define a custom base element (not body) HOT 1
- iOS 16 Safari has width/size issues with wide content HOT 2
- This fork from vercel seems to fix some issues HOT 1
- Add example using React hooks HOT 1
- On IOS disableBodyScroll() makes element.scrollIntoView() not working HOT 1
- ESM build broken, causes scroll-to-top on iOS HOT 3
- Using logical css property instead of padding-right
- scroll reset happens when use disableBodyScroll HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from body-scroll-lock.