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

[BUG] useScrollLock - Do not leave inline styles if they weren't present before the lock #520

Closed
kyrylo-soulandwolf opened this issue Mar 3, 2024 · 2 comments · Fixed by #521
Labels
bug Something isn't working

Comments

@kyrylo-soulandwolf
Copy link
Contributor

kyrylo-soulandwolf commented Mar 3, 2024

Describe the bug

  1. At the moment the hook leaves overflow and padding-right on the target after unlocking. Even though it is a computed value from before the lock, it can change in CSS for various reasons (and not considered in future locks) and will always be overridden by inline styles. These 2 values should be reverted to the initial value if they existed inline, otherwise removed completely which will make the styles on the target the same as before the lock.

Here's an example how tua-body-scroll-lock does this.

  1. The second problem is that the global scrollbar is not part of the body, so if lockTarget is a body element scrollbarWidth will always be 0. There should be a special case for body as a target and use window.innerWidth instead of target.current.offsetWidth to get the width with the global scrollbar.

To Reproduce

Codesandbox repro link

  1. Just lock and unlock any element.
  2. Same thing but using body as a target

Expected behavior

After unlocking, the target element should have initial inline styles or no inline styles if they weren't present.

Additional context

No response

@kyrylo-soulandwolf kyrylo-soulandwolf added the bug Something isn't working label Mar 3, 2024
@kyrylo-soulandwolf
Copy link
Contributor Author

The tests seem to pass by returning false positives because window.getComputedStyle(...) returns an empty string instead of the actual value

@kyrylo-soulandwolf
Copy link
Contributor Author

Opened a pull request #521 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant