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

Further fine tune scroll locking on iOS #2891

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue that I only noticed in a production build and not in the local development
version (potentially related to strict mode?).

However, we are trying to scroll lock the page on iOS, a way to do this is to add
overscroll-behavior: contain; and call event.preventDefault() in the touchmove event. While
this works great, we have to account for scrollable elements inside the allowed containers (e.g.:
a scrollable table in a dialog).

We did this by checking whether or not the event.target or any of its parent were scrollable. The
heuristic we used was two-fold:

  1. Does the computed style have overflow: auto | scroll;, overflow-x: auto | scroll; and overflow-y: auto | scroll;
  2. Or, is there an overflow happening element.scrollWidth > element.clientWidth or element.scrollHeight > element.clientHeight

The issue is the first step, if an overflow property exists but there is no overflowing happening
then the overscroll-behavior for some reason doesn't have any effect and it will result in the
main page being scrollable.

Purely relying on step 2 seems to fix this issue.

Copy link

vercel bot commented Dec 21, 2023

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

Name Status Preview Comments Updated (UTC)
headlessui-react ❌ Failed (Inspect) Dec 21, 2023 1:47am
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 21, 2023 1:47am

@RobinMalfait RobinMalfait merged commit 20b3b65 into main Dec 21, 2023
7 of 8 checks passed
@RobinMalfait RobinMalfait deleted the fix/improve-ios-scroll-locking branch December 21, 2023 01:49
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

Successfully merging this pull request may close these issues.

1 participant