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

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

Closed
jagustin opened this issue Feb 7, 2023 · 14 comments
Closed

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

jagustin opened this issue Feb 7, 2023 · 14 comments
Assignees

Comments

@jagustin
Copy link

jagustin commented Feb 7, 2023

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
Copy link
Member

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
Copy link
Author

jagustin commented Feb 7, 2023

@RobinMalfait the repository was updated. Thank you.

@RobinMalfait
Copy link
Member

@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
Copy link
Author

jagustin commented Feb 7, 2023

@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
Copy link
Member

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

@RobinMalfait
Copy link
Member

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

image

🧐

@bhaidar
Copy link

bhaidar commented Apr 14, 2023

Hey! Is there a solution to this? Thanks

@danielbichuetti
Copy link

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

Maybe a regression?

@LeonDWong
Copy link

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
Copy link

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

@RobinMalfait
Copy link
Member

Hey!

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

  • npm install @headlessui/react@next

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
Copy link

Any solution to this problem? facing the same issue

@nazaninsoleimanian
Copy link

nazaninsoleimanian commented Jun 11, 2024

@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!

@adrianxadamn
Copy link

adrianxadamn commented Feb 11, 2025

how do we prevent touch-action from applying to element that it shouldn't even apply to? Depending on how you scroll on a mobile phone while simultaneously opening a component (drawer) will somehow add touch-action:none style to any element that you touch.

Update:
Depending on your use case, adding the blow to will mitigate your issues. #3378 (comment)

onTouchMove={(e) => {
  e.stopPropagation()
}}
onTouchStart={(e) => {
  e.stopPropagation()
}}

and adding these styles to override touch-action:none that headless-ui keeps applying to these elements.

html, body {
  /* prevent headless-ui/react bug from applying touch-action:none to these elements */
  touch-action: auto !important
}

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

No branches or pull requests

9 participants