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

Improve scroll locking on iOS #2100

Merged
merged 3 commits into from Dec 15, 2022
Merged

Improve scroll locking on iOS #2100

merged 3 commits into from Dec 15, 2022

Conversation

RobinMalfait
Copy link
Collaborator

This PR further improves scroll locking on iOS.

Instead of using the "simple" hack with the position: fixed; implemented in #1830 we now went back to the touchmove implementation we used before.

The position: fixed; causes some annoying issues. For starters, on iOS you will now get a strange gap (due to safe areas). Some applications also saw "blank" screens based on how the page was implemented.

We also saw some issues internally, where clicking on a link that changes the scroll position on the "main" page from within the Dialog didn't work properly.

Think about something along the lines of:

<a href="#interesting-link-on-the-current-page">Interesting link on the page</a>

This doesn't work becauase the page is now fixed, and there is nothing to scroll...

Instead, we now use the touchmove implmentation again. The problem with this last time was that this disabled all touch move events. This is obviously not good.

Luckily, we already have a concept of "safe containers". This is what we use for the outside click behaviour as well. Basically in a Dialog, your Dialog.Panel is the safe container. But also third party DOM elements that are rendered inside that Panel (or as a sibling of the Dialog, but not your main app).

We can re-use this knowledge of "safe containers", and only cancel the touchmove behaviour if this didn't happen in any of the safe containers.

Fixes: #1900

Instead of using the "simple" hack with the `position: fixed;` we now
went back to the `touchmove` implementation.

The `position: fixed;` causes some annoying issues. For starters, on iOS
you will now get a strange gap (due to safe areas). Some applications
also saw "blank" screens based on how the page was implemented.

We also saw some issues internally, where clicking changing the scroll
position on the main page from within the Dialog.

Think about something along the lines of:
```html
<a href="#interesting-link-on-the-current-page">Interesting link on the page</a>
```

This doesn't work becauase the page is now fixed, and there is nothing
to scroll...

Instead, we now use the `touchmove` again. The problem with this last
time was that this disabled _all_ touch move events. This is obviously
not good.

Luckily, we already have a concept of "safe containers". This is what we
use for the `outside click` behaviour as well. Basically in a Dialog,
your `Dialog.Panel` is the safe container. But also third party DOM
elements that are rendered inside that Panel (or as a sibling of the
Dialog, but not your main app).

We can re-use this knowledge of "safe containers", and only cancel the
`touchmove` behaviour if this didn't happen in any of the safe
containers.
@vercel
Copy link

vercel bot commented Dec 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
headlessui-react ✅ Ready (Inspect) Visit Preview Dec 15, 2022 at 2:56PM (UTC)
headlessui-vue ✅ Ready (Inspect) Visit Preview Dec 15, 2022 at 2:56PM (UTC)

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