Commit 6b5709a
authored
Fix touch actions on iOS after entering disallowed area (#3801)
This PR fixes an issue where if you have an open Dialog on iOS that once
you interacted with an area otuside of the dialog, you could no longer
scroll or zoom the dialog itself anymore until it closed and reopened.
The reason this was happening is that on `touchstart` we checked whether
we are in an allowed area or not.
- If we are in an allowed area, add `overscroll-behavior: contain` to
the scrollable area to prevent scrolling the body behind it.
- If we are not in an allowed area, add `touch-action: none` to the
element you were touching to prevent any other touch events from being
fired.
The problem with this is that we never reset the state until the dialog
is closed (and eventually unmounted).
So to solve the problem, every time we get a `touchstart` event, we
reset those CSS properties to their previous values, and then check
again whether we are in an allowed area or not.
Note: the `touchstart` event listener is set on the document itself, so
we still get the event even if `touch-action: none` was set on the
target element.
## Test plan
Made 2 videos with a before / after comparison. The reproduction used is
from #3234. The steps I'm applying here are:
1. Open the dialog by tapping on the toggle button
2. Scroll inside the dialog
3. Pinch to zoom inside the dialog
4. Tap outside / scroll outside the dialog to show that you can't with
the outside
5. Scroll inside the dialog again
6. Pinch to zoom inside the dialog again
**Before:**
1. ✅ Open the dialog by tapping on the toggle button
2. ✅ Scroll inside the dialog
3. ✅ Pinch to zoom inside the dialog
4. ✅ Tap outside / scroll outside the dialog to show that you can't with
the outside
5. ❌ Scroll inside the dialog again
6. ❌ Pinch to zoom inside the dialog again
https://github.com/user-attachments/assets/d79d9794-3732-4201-a4c9-43ea36d302ce
**After:**
1. ✅ Open the dialog by tapping on the toggle button
2. ✅ Scroll inside the dialog
3. ✅ Pinch to zoom inside the dialog
4. ✅ Tap outside / scroll outside the dialog to show that you can't with
the outside
5. ✅ Scroll inside the dialog again
6. ✅ Pinch to zoom inside the dialog again
https://github.com/user-attachments/assets/f6c1c765-3c8c-4d3c-91c2-1b43507f6434
Fixes: #3234
Closes: #36021 parent 433b174 commit 6b5709a
File tree
2 files changed
+20
-15
lines changed- packages/@headlessui-react
- src/hooks/document-overflow
2 files changed
+20
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
Lines changed: 19 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | | - | |
| 99 | + | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
| |||
0 commit comments