tailwindlabs / headlessui

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
https://headlessui.com
MIT License
25.5k stars 1.05k forks source link

Dialog Scrollbar doesn't work properly on Mobile Devices #2259

Closed jagustin closed 7 months ago

jagustin commented 1 year ago

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

1.7.10

What browser are you using?

Chrome and Safari on iPhone 13 Pro

Reproduction URL

Repo https://github.com/jagustin/modal-tailwind-test Instructions: Scroll down until the button "Open Dialog" and tap it. When the Dialog is opened scroll up and down on the left of the screen you will notice that the body will scroll (The Dialog don't need to scroll, the content is not enough to cover the screen but the scrollbar appear..)

Video https://drive.google.com/file/d/1FV-TcZK_ZxtYEsDIjaBorD-1QeNip31b/view?usp=share_link

Describe your issue

When the Dialog Modal is opened and the body has been scrolled before, the scroll event works for the body scroll but not for the Dialog Modal. That only happens on mobile devices. I am including a repo and video to help you understand the issue.

RobinMalfait commented 1 year ago

Hey! Thank you for your bug report! Much appreciated! 🙏

Please make sure that you commit and push all the necessary code to reproduce this bug. The current reproduction doesn't have an open dialog button.

IMG_7804

jagustin commented 1 year ago

@RobinMalfait the repository was updated. Thank you.

RobinMalfait commented 1 year ago

@jagustin I can't seem to reproduce this (I'm iPhone 14 Pro Max, iOS 16.3). Can you try and clear your node_modules and your .next cache?

rm -rf ./node_modules .next
npm install
npm run dev

This is a bug we used to have in Headless UI, but that should have been solved already, my guess/hope is that you have a bogus build and some old version of Headless UI despite installing the latest version.

jagustin commented 1 year ago

@RobinMalfait I just removed the cache and install everything. The issue continue https://drive.google.com/file/d/1hXCKCGbxF5JfbKoCxkOr8hqKzSKWsCTK/view?usp=share_link

To replicate as soon as the dialog is opened, you could scroll up and down very close to end of the screen (left side). It looks like the overlay doesn't cover all the screen and the gesture take the body scroll.

RobinMalfait commented 1 year ago

@jagustin it took a while, but I can reproduce it now. Will have a look and keep you posted.

RobinMalfait commented 1 year ago

So here is a fun discovery, I can reproduce it using the "Single Tab" browser setting, but not using the "Tab Bar".

image

🧐

bhaidar commented 1 year ago

Hey! Is there a solution to this? Thanks

danielbichuetti commented 1 year ago

Facing the same issues with Chrome on iPhone 6 and iPhone 14 iOS 15.

Maybe a regression?

LeonDWong commented 1 year ago

I find out the problem is that body is still scrollable when dialog appeared in iOS safari(webkit based browser). Here's my solution, just make body not scrollable after dialog appeared, also set height by marginTop which is same as scrollTop, at least it does the trick for me.

  const makeBodyNotScrollable = () => {
    document.body.style.height = `calc(100vh - ${document.body.style.marginTop})`;
    document.body.style.overflowY = 'hidden';
  }

  return (
    <Transition appear show={visible} afterEnter={makeBodyNotScrollable}>
      <Dialog>
      </Dialog>
    </Transition>
  )

Hope this helps.

binhit92 commented 11 months ago

Hi guys, i have same issues with browsers on ios 14, dialog can not show. @RobinMalfait maybe you have any solution?

RobinMalfait commented 7 months ago

Hey!

I believe this is solved now if you use the latest next release:

This next release is for our upcoming 2.0 release. I'm working on a 1.7.x release right now to backport the necessary changes. But you can already test things. 👍

1abdurRehman commented 4 months ago

Any solution to this problem? facing the same issue

nazaninsoleimanian commented 2 months ago

@RobinMalfait

Hey!

I'm still experiencing this issue with browsers on iOS.I use nexjs 14 and headless ^2.0.0-alpha.4, I tried installing @headlessui/react@next and used the makeBodyNotScrollable function that you suggested above, but the scrollbar in the dialog still doesn't work.

When we click on any element on the modal, a touch-action: none style is applied to that element, which I think is the reason for not being able to scroll on mobile iOS. Ensure your modal and its elements do not get this style by overriding it or removing it when applied.

Thank you!