I have an browser app that dynamically shows content that can be shorter or longer than the available screen size. On desktop browsers, this causes vertical scrollbar to appear/disappear, which makes the content "jump" left and right.
To avoid this, I add style="overflow-y: scroll"
to the body
tag, which forces the scrollbar to always display - the scrollbar is just disabled if the content is shorter than the screen.
The problem comes when I use the material-ui
SwipeableDrawer
component to show a sliding option menu. Viewing the DOM in the browser inspector, it seems material-ui
actively removes my overflow-y
styling on the body
tag when it shows the menu, but then doesn't put it back when it removes the menu.
- Example app published on Netlify
- Source code
- The screen-shot below shows the content is stable at first when the disabled scrollbar is visible, then shows the content jumping left/right after the menu has been displayed.
This only happens on desktop, reproduced with both Chrome and Firefox. It doesn't happen on mobile (iOS, for example) because the scrollbar on mobile devices is displayed "on top" of the content.
I don't want to track what material-ui
is doing and add/remove padding - I'm pretty sure material-ui
does this behaviour for other components as well (poppers, tooltips, etc.) Tracking all those components and fiddling with padding will be error-prone (not to mention tedious).
Can I somehow make the vertical scrollbar display "on top" of the content like it does in a mobile browser? I'd have to add padding to make sure nothing gets obscured, but at least it'd be static - so once the problem is fixed it'll stay fixed.