nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Layout shift when opening Modal or Select

Open wilhus opened this issue 11 months ago • 18 comments

HeroUI Version

2.7.2

Describe the bug

As previously reported in https://github.com/heroui-inc/heroui/issues/1027, there is a layout shift in the background when opening a Modal or Select component. This happens both locally and on the actual HeroUI documentation page.

Your Example Website or App

https://www.heroui.com/docs/components/select

Steps to Reproduce the Bug or Issue

  1. Go to Select or Modal component
  2. Open Selection or Modal
  3. Notice the layout shift

Expected behavior

There should be no layout shift.

Screenshots or Videos

https://github.com/user-attachments/assets/a4acc187-708d-44d1-b23b-e7e563a2af9c

Operating System Version

macOS Sonoma

Browser

Firefox

wilhus avatar Feb 20 '25 08:02 wilhus

from my side I couldn't seethe layout shifting on Firefox

wingkwong avatar Feb 20 '25 09:02 wingkwong

from my side I couldn't seethe layout shifting on Firefox

I get it on Safari and Chrome as well.

wilhus avatar Feb 20 '25 09:02 wilhus

@wingkwong Judging by recent comments in the #1027 issue, there seems to be multiple people who still run into this. And it looks really bad. So would really appreciate if we can find out what's causing this.

Out of interest, what does your setup look like (OS etc.)?

wilhus avatar Feb 20 '25 09:02 wilhus

I'm using mac OS ventura and couldn't reproduce across different browsers. By pure guess, I think some users by default would have a scrollbar on their browser, when they open the select, the scrollbar is hidden causing the layout shift.

wingkwong avatar Feb 20 '25 09:02 wingkwong

I'm using mac OS ventura and couldn't reproduce across different browsers. By pure guess, I think some users by default would have a scrollbar on their browser, when they open the select, the scrollbar is hidden causing the layout shift.

Doesn't the scrollbar show for you? It always shows for me when there's overflow 🤔 Does it only show for you once you scroll? I guess that could be the issue then

wilhus avatar Feb 20 '25 10:02 wilhus

This is what I see when at the top

Image

wilhus avatar Feb 20 '25 10:02 wilhus

Because the scrollbar toggles between showing and hiding, the scrollbar has a width. It might be possible to prevent scrolling only by intercepting scroll events, rather than by hiding the scrollbar through the style.

AnYiEE avatar Feb 20 '25 10:02 AnYiEE

+1

The same problem with Dropdown. However, there is no such problem in Popover.

Q0 avatar Feb 20 '25 11:02 Q0

I also have this issue in my Chrome browser. It should be caused by the display and hiding of the scroll bar. Calculating the current width of the scroll bar when the component is opened and then compensating for the layout should solve the problem.

linyonglu avatar Feb 20 '25 12:02 linyonglu

I can confirm that I also encounter this issue with the Select modal window, where an extra scroll appears in some layouts when a value is selected. To reproduce these defects, use a mobile phone.

ETOPS7 avatar Feb 22 '25 19:02 ETOPS7

when open modal have style in line { color-scheme: dark; padding-right: 16px; overflow: hidden; }

but CSS padding-right: 16px; not working cause

html { font-size: 16px; padding: 0 !important; <====== !important on The reason for this line overflow-x: hidden; scroll-padding-top: 64px; }

a44c2934 avatar Feb 24 '25 04:02 a44c2934

Dude

https://github.com/user-attachments/assets/3f7951dc-406a-4cff-926d-7f7ab56273f2

I am so tired to make this UI kit work. Question: Why the hell u would use hook to add dynamic "padding-right" to html tag?

BadMachine avatar Feb 25 '25 15:02 BadMachine

In my case it is pretty bad, i'm sure this bug came right after we upgraded from NextUI to HeroUI

https://github.com/user-attachments/assets/8d713f1a-62e6-4aeb-81fa-aa2fc2966bc5

schrodd avatar Mar 17 '25 17:03 schrodd

I was able to prevent this issue from happening setting this on my main css file

html { padding-right: 0 !important; overflow: visible !important; }

Image

Those styles are being applied whenever a select is open, but i don't know what's the need for those. Without that everything works just fine. I'm still testing other HeroUI's components to see if something broke.

schrodd avatar Mar 17 '25 17:03 schrodd

This is still an issue on the latest version (2.7.8). It seemed weird to me why it would add this padding only on chrome. @schrodd's fix seem to work wonderfully, I hope it doesn't break anything else (although I don't see why it would)

UltraWelfare avatar May 20 '25 08:05 UltraWelfare

The same questioin🙋🏻‍♀️

katakuta avatar May 22 '25 01:05 katakuta

best and most elegant solution for me is:

html {
    scrollbar-gutter: stable;
}

nvmxre avatar Jun 08 '25 17:06 nvmxre