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: Modal Dialog Adds A None Existent Scrollbar Spacing To Backdrop #3040

Open
MunkeeJuice opened this issue May 17, 2024 · 13 comments
Open
Labels

Comments

@MunkeeJuice
Copy link

What version of daisyUI are you using?

4.10.5

Which browsers are you seeing the problem on?

Chrome, Edge

Reproduction URL

https://play.tailwindcss.com/V7z8gOaVTT

Describe your issue

When a modal dialog opens the backdrop behind shifts left due to a space appearing where the y-scrollbar should be, even though it is not showing a scrollbar before the dialog is opened.

Copy link

Thank you @MunkeeJuice for reporting issues. It helps daisyUI a lot 💚
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

@MunkeeJuice MunkeeJuice changed the title bug: Modal Dialog Cause Add None Existent Scrollbar Spacing To Backdrop bug: Modal Dialog Adds A None Existent Scrollbar Spacing To Backdrop May 17, 2024
@MunkeeJuice
Copy link
Author

As far as i can see this only happens on Chromium based browsers, the issue does not occur in firefox

@keksiskela
Copy link

Same behavior with drawers (the code is pretty much identical to stock navbar + drawer component); only on Chrome, and only on desktop. Seems to affect all overlays.

https://play.tailwindcss.com/Dgv6PeF5C4

@simonechebelnome
Copy link

I'm having the same problem, did anyone find a solution? I've tried overriding the ::-webkit-scrollbar pseudo class with no results

@mpoweredo
Copy link

mpoweredo commented May 25, 2024

html {
  scrollbar-gutter: auto !important;
}

seems to fix the issue

@valeiras
Copy link

html {
  scrollbar-gutter: auto !important;
}

seems to fix the issue

I tried this and it worked great! But then, when there really was a scrollbar in the background, it wouldn't create it. I finally went with:

html {
  scrollbar-gutter: stable;
}

The dummy scrollbar still appears, but there is no layout shift

@Sergiocobra
Copy link

I'm still having this same issue, is there any improvement on this?

@dbgordon09
Copy link

dbgordon09 commented Jul 25, 2024

TL;DR:

:root:has(
    :is(
        .modal-open,
        .modal:target,
        .modal-toggle:checked + .modal,
        .modal[open]
      )
  ) {
  scrollbar-gutter: unset;
}

@valeiras' comment led me to investigate the scroll-gutter property on <html> when a DaisyUI modal is open. If you check the :root element when a modal is open you will find. 🕵️

:root:has(
    :is(
        .modal-open,
        .modal:target,
        .modal-toggle:checked + .modal,
        .modal[open]
      )
  ) {
  overflow: hidden;
  scrollbar-gutter: stable;
}

The scrollbar-gutter: stable is the culprit that creates the gutter when a dialog is open.

Adding:

:root:has(
    :is(
        .modal-open,
        .modal:target,
        .modal-toggle:checked + .modal,
        .modal[open]
      )
  ) {
  scrollbar-gutter: unset;
}

Resolves the issue for me! 🥳

I originally thought it was a chromium user-agent stylesheet for max-height and max-width referenced by @t3dotgg in his brilliant video on it, but alas that was not the case here.

Hope this helps someone ✌️

@ross-byrne
Copy link

I'm having the same issue when a drawer is open. Only seems to effect Chrome based browsers. I've resolved the issue in my app with the following css:

html:has(.drawer-toggle:checked) {
    scrollbar-gutter: auto;
}

@abegehr
Copy link

abegehr commented Oct 7, 2024

It's worth mentioning that this only seems to occur when the scrollbar is set to "always show" in user's system preferences.
Wondering why scrollbar-gutter is set to stable by drawer-toggle in the first place 🤔

@tapizquent
Copy link

:root:has(
    :is(
        .modal-open,
        .modal:target,
        .modal-toggle:checked + .modal,
        .modal[open]
      )
  ) {
  scrollbar-gutter: unset;
}

This is great, but now when there actually is a scrollbar, the scrollbar disappears and there is a layout shift.

@saadeghi
Copy link
Owner

Well...
There's no way for CSS to check if scrollbar exists or not and add gutter only if scrollbar exists.

  1. If modal adds gutter
  • if there's scrollbar, all good.
  • if there's no scrollbar, layout will shift
  1. if modal doesn't add gutter
  • if there's scrollbar, layout will shift
  • if there's no scrollbar, all good

So it's a tradeoff. But since the majority of websites have a vertical scroll, option 1 would make more sense, which is the default in daisyUI.

This is not an issue on Android, Mac, iOS, some Linux systems since the scrollbar doesn't occupy a physical space in the first place. It's only an issue on Windows and some Linux systems where scrollbars occupy a physical space.

I am aware of this issue but doing each of first or second method have their own side effects, we should go with safer option, in favor of majority.

In the upcoming version of daisyUI (5) it will be possible to choose if you want gutter or not.

@przwr
Copy link

przwr commented Nov 13, 2024

I have the same issue - was able to patch it with

html {
  scrollbar-gutter: auto !important;
}

seems to fix the issue

It fixes issue for me, because I don't use top level scrollbar anyways.

I found out that issue is present since DaisyUI version 4.7.0
The issue with Modal doing the same was also fixed with this CSS snippet. For modal, I found out that bug was introduced in version 4.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests