Skip to content
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

Implementation does not reserve the scrollbar width #9

Closed
martinkutter opened this issue Apr 10, 2018 · 14 comments
Closed

Implementation does not reserve the scrollbar width #9

martinkutter opened this issue Apr 10, 2018 · 14 comments

Comments

@martinkutter
Copy link
Contributor

Thank you for this easy to use library.
Unfortunately, it doesn't quite fit our application.
The content of our site is centered. If the user opens a popup and we execute "disableBodyScroll", the scrollbar is removed. This makes the body slightly wider than before and the centered elements in the background jump to the right.

In this case it would make sense to reserve the space for the scrollbar. Could the following solution, possibly optional, fit to the library? Then I would create a PullRequest.

var setOverflowHidden = function setOverflowHidden() {
  // Setting overflow on body/documentElement synchronously in Desktop Safari slows down
  // the responsiveness for some reason. Setting within a setTimeout fixes this.
  setTimeout(function () {
    var padding = window.innerWidth - document.body.clientWidth;
    document.body.style.paddingRight = padding + 'px';
    document.body.style.overflow = 'hidden';
    document.documentElement.style.overflow = 'hidden';
  });
};

var setOverflowAuto = function setOverflowAuto() {
  // Setting overflow on body/documentElement synchronously in Desktop Safari slows down
  // the responsiveness for some reason. Setting within a setTimeout fixes this.
  setTimeout(function () {
    document.body.style.paddingRight = 0;
    document.body.style.overflow = 'auto';
    document.documentElement.style.overflow = 'auto';
  });
};
@willmcpo
Copy link
Owner

hi @martinkutter

thanks for the code - happy for you to create the PR.

Once you create it, I'll try to have it reviewed quickly.

@FL3NKEY
Copy link

FL3NKEY commented Apr 11, 2018

You are welcome.

https://github.com/FL3NKEY/scroll-lock

@martinkutter
Copy link
Contributor Author

@FL3NKEY thanks for the recommendation. We want to use the library for a large React app, so abstraction is a minimum requirement. However, this is not possible due to the fixed CSS class names. This means that the library cannot simply be replaced later if problems arise.

I'm on my way to the React Conference in Amsterdam/NL. When I get back I'll take care of the PR.

@Tobbe
Copy link

Tobbe commented Apr 28, 2018

Can't wait for the PR. I need this as well! :)
@martinkutter Any progress?

@FL3NKEY
Copy link

FL3NKEY commented Apr 28, 2018

@martinkutter updated, check out 🤗

@martinkutter
Copy link
Contributor Author

Sorry for the delay. Let me look at the solution from @FL3NKEY next week and I'll get back to you.

@willmcpo
Copy link
Owner

@martinkutter 👍 let me know how it goes - if you end up not putting a PR through, I'll adapt your suggestion and create a PR for body-scroll-lock.

@martinkutter
Copy link
Contributor Author

martinkutter commented May 2, 2018

Thanks for your patience 😅. I created a PR. #14
@willmcpo please have a look and if everything fits I would be happy about a suggestion for the docs.

@FL3NKEY
Copy link

FL3NKEY commented May 2, 2018

@martinkutter what's the problem using my library?

@martinkutter
Copy link
Contributor Author

@FL3NKEY As I mentioned before, we use this library in a large React application based on plugins. For example, a normal use case is that one component activates the scrolllock, then a second component is mounted, which also activates the scrolllock. If the first component deactivates the scrolllock, it is not considered that it is still needed by the second component. So I decided to continue using this library, which can handle it correctly.

@FL3NKEY
Copy link

FL3NKEY commented May 2, 2018

@martinkutter oh, i got it, work at that 🤗

@FL3NKEY
Copy link

FL3NKEY commented May 3, 2018

@martinkutter updated

@willmcpo
Copy link
Owner

willmcpo commented May 3, 2018

@martinkutter thanks I've reviewed it and no problems with the delay 👍

@willmcpo
Copy link
Owner

willmcpo commented May 3, 2018

PR #14 pending minor change and then will merge

@willmcpo willmcpo closed this as completed May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants