Commit b0615ad
authored
Ensure sibling
This PR fixes an issue where opening a sibling dialog doesn't allow you
to scroll the second (top most) dialog on iOS anymore.
The issue here is that on iOS we have to do a lot of annoying work to
make the dialog behave like a dialog and prevent scrolling _outside_ of
the dialog.
To make this all work, we PUSH and POP some information to know what the
top-most dialog is. The moment there is 1 open dialog, and as long as
there is 1 dialog we scroll lock the page, the moment there are 0
dialogs again we unlock the page again.
Each dialog also has a set of "allowed containers", these are just
container DOM nodes where we allow scrolling.
But the issue is that we were dealing with stale data. These are the
events you see when we open dialogs:
```
[Log] Open dialog #1
[Log] PUSH
[Log] SCROLL_PREVENT → We start preventing scroll because there is 1 dialog
[Log] Open dialog #2
[Log] PUSH → We opened a second dialog, but the `SCROLL_PREVENT`
→ was already active and doesn't re-evaluate
[Log] POP → POP from dialog #1 because not the top-most anymore
```
Any time we `PUSH` we also track new meta data with the allowed
containers. But
we were already preventing scroll, so we had stale meta data.
To solve this, I can think of 2 solutions:
1. The moment we POP, we also SCROLL_ALLOW again, but realize that we
still have 1 dialog open, so we SCROLL_PREVENT again. This just feels
wrong to me though.
2. Any time we PUSH / POP, we re-evaluate the meta data, and when
receive the meta data in the SCROLL_PREVENT event listeners, we call the
function to get the latest meta data not the old stale data.
## Test plan
In both scenario's I first open the dialog, then scroll.
**before:**
https://github.com/user-attachments/assets/e4747e14-c80e-4f64-8ea0-ec43b1d2283d
**after:**
https://github.com/user-attachments/assets/c5cf1d59-1186-4a9f-84c7-4a67339f2d01
Fixes: #3378Dialog components are scrollable on mobile (#3796)1 parent f96538e commit b0615ad
File tree
3 files changed
+29
-8
lines changed- packages/@headlessui-react
- src/hooks/document-overflow
3 files changed
+29
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
Lines changed: 19 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
| 65 | + | |
62 | 66 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
66 | 80 | | |
67 | 81 | | |
68 | 82 | | |
| |||
0 commit comments