My browser app displays content dynamically, which can vary in length compared to the screen size. This causes a vertical scrollbar to appear and disappear on desktop browsers, leading to the content shifting left and right.
To prevent this, I apply style="overflow-y: scroll"
to the body
tag, ensuring the scrollbar is always visible - it simply remains disabled when the content is shorter than the screen.
The issue arises when using the material-ui
SwipeableDrawer
component for a sliding menu option. It appears that material-ui
actively removes my overflow-y
styling on the body
tag when displaying the menu, but fails to reinstate it afterward.
- Here's an example app published on Netlify.
- Check out the source code here.
- A screenshot illustrates how the content initially remains stable with the disabled scrollbar visible, only to shift left/right once the menu is shown.
https://i.sstatic.net/Swdi8.gif
This behavior exclusively occurs on desktop, as both Chrome and Firefox exhibit the issue. However, mobile devices like iOS do not experience this problem since the scrollbar is displayed over the content.
I prefer not to track and modify material-ui
's behavior by adding/removing padding, especially considering that other components (e.g., poppers, tooltips) might behave similarly. Managing multiple components and adjusting padding seems error-prone and cumbersome.
Is there a way to have the vertical scrollbar overlay the content like it does on mobile browsers? Adding padding to ensure visibility would be necessary, but at least the solution would remain static, resolving the issue persistently.