react-spectrum: React Aria's usePreventScroll hook causes whitespace shown on desktops from padding-right on html element
๐ Bug Report
When the usePreventScroll
hook is used on a non-mobile device (with a scrollbar), a strip of whitespace shows up. This happens when a element with a 100%
width and height is added to the DOM.
The problem is caused by the padding-right
thatโs added to the html element.
๐ค Expected Behavior
The whitespace should not be visible on the right side of the page.
๐ฏ Current Behavior
The padding-right
shows up at the right side of the page.
๐ Possible Solution
The body element styled should get overflow: hidden
assigned. Also possible to give the body element the same background color as the fullscreen container, which is not optimal.
๐ฆ Context
See the right side of the page, used in a new Next.js application.
๐ป Code Sample
๐ Your Environment
Software | Version(s) |
---|---|
react-aria | 3.1.0 |
Browser | Google Chrome |
Operating System | Windows 10 64bit |
๐งข Your Company/Team
๐ท Tracking Issue (optional)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 15 (5 by maintainers)
Any updates on this issue? It seems to still be a current thing
react-spectrum
still making progress? the best solution has already been provided above with compensation, but itโs been a yearI think the best way to solve this issue is following steps
html
element add custom classNamecompensate-for-scrollbar
body
element when isActive, AND generate styles for this classNameWhen is not active - nothing.
width: 100%
useleft: 0; right:0
to work correctly with padding compensation.This technique is well known and used in multiple popular libraries like
fancybox
.At this moment I donโt have any solution to do the same thing with
usePreventScroll
as I described to achieve the same result. I know this hook as a whole aria library is not related to styling, but I think this is a good step towards users.@pascalduez weโll need to find some other way than a callback for usePreventScroll, thatโd potentially require listening to every dialog etc that makes use of usePreventScroll, in a large shared code base, this could be untenable. We donโt have another idea at this time, so all ideas are welcome.