-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Drawer causing overflow/scrollbar on right side of page on desktop #2859
Comments
Thank you @AndrewB-S
for reporting issues. It helps daisyUI a lot 💚
|
Encountered the same problem, reproduced the demo
It seems that there is something wrong with the following style daisyui/src/utilities/unstyled/drawer.css Line 22 in b155f9c
|
It seems that the root cause of the problem has been located. |
The pipeline I have used. It will create a commit for update snapshot, If test faild. Maybe submitting a PR will serve the purpose of automated testing. Hope this helps.
|
That's scrollbar gutter. Whether you like it or not there is a reason it exists: if the page has scrollable content, when we open the drawer it is expected for the page to stop being scrolled and it is expected for the sidebar to get scrolled. In this situation, if the page itself has a standard scrollbar (Windows, Linux, Mac if enable manually) it will suddenly hide the the scrollbar and causes the page to shift for the width of scrollbar. Scrollbar gutter is a CSS rule to avoid this layout shift. If there was a better solution I would use it of course but preserving the scrollbar width is totally more acceptable than a layout shift. Let me know if you have any questions. |
It looks like the issue might be the fact that the lines A possible solution would be to find a way to make the make the gutter appear only when the html element is overflowing. |
I can understand the need for this feature. But is there any way we can prevent scroll from displaying? May be If my content area is only 100vh. And the drawer-side will never overflow. <div className="drawer">
<input id="my-drawer" type="checkbox" className="drawer-toggle" />
<div className="drawer-content">
{/* Page content here */}
<label htmlFor="my-drawer" className="btn btn-primary drawer-button">Open drawer</label>
</div>
--- <div className="drawer-side">
+++ <div className="drawer-side drawer-side-no-scroll">
<label htmlFor="my-drawer" aria-label="close sidebar" className="drawer-overlay"></label>
<ul className="menu p-4 w-80 min-h-full bg-base-200 text-base-content">
{/* Sidebar content here */}
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div> |
From another perspective, I think combined is better than reduction. May be a The following modification might be better? ---html:has(.drawer-toggle:checked) {
+++html:has(.drawer-toggle:checked ~ drawer-side-sticky) {
@apply overflow-y-hidden;
scrollbar-gutter: stable;
} <div className="drawer">
<input id="my-drawer" type="checkbox" className="drawer-toggle" />
<div className="drawer-content">
{/* Page content here */}
<label htmlFor="my-drawer" className="btn btn-primary drawer-button">Open drawer</label>
</div>
--- <div className="drawer-side">
+++ <div className="drawer-side drawer-side-sticky">
<label htmlFor="my-drawer" aria-label="close sidebar" className="drawer-overlay"></label>
<ul className="menu p-4 w-80 min-h-full bg-base-200 text-base-content">
{/* Sidebar content here */}
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div> |
If there's a way, let me know.
You can remove the scrollbar gutter using |
@saadeghi Sorry to bother you, it seems that this classname does not take effect. It will be override by the drawer's style |
But when there are no vertical scrollbars, the gutter appears and makes the layout shift anyway. To me, and until CSS will support detecting content overflow, using JavaScript is a better solution. Some preliminary test got this simple solution working (using Next.js) : /* global.css */
html {
scrollbar-gutter: auto !important;
}
html:has(body.content-overflow-y) {
scrollbar-gutter: stable !important;
} // ui.ts
const observer = new MutationObserver(() => {
const body = document.body;
const hasSscrollbar =
body.scrollHeight != Math.max(body.offsetHeight, body.clientHeight);
if (hasSscrollbar) {
body.classList.add("content-overflow-y");
} else {
body.classList.remove("content-overflow-y");
}
});
observer.observe(document.body, { childList: true, subtree: true }); That's it. The gutter only appears when there is a vertical scrollbar on |
I just added this in my
|
What version of daisyUI are you using?
4.7.2
Which browsers are you seeing the problem on?
Chrome, Firefox
Reproduction URL
https://play.tailwindcss.com/IQNlGqiMLf
Describe your issue
There is a bar that is created on the right side of the screen when the drawer is toggled open. In my own testing it happened with every version of the drawer available, with no other content present.
The text was updated successfully, but these errors were encountered: