@@ -97,7 +97,6 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
97
97
if ( inAllowedContainer ( e . target as HTMLElement ) ) {
98
98
// We are in an allowed container, however on iOS the page can still scroll in
99
99
// certain scenarios...
100
-
101
100
let rootContainer = e . target
102
101
while (
103
102
rootContainer . parentElement &&
@@ -113,20 +112,32 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
113
112
// portal, its over.
114
113
scrollableParent . dataset . headlessuiPortal !== ''
115
114
) {
116
- if ( scrollableParent . scrollHeight > scrollableParent . clientHeight ) {
115
+ // Verify that we are in a scrollable container (which may or may not overflow yet)
116
+ let css = window . getComputedStyle ( scrollableParent )
117
+ if ( / ( a u t o | s c r o l l ) / . test ( css . overflow + css . overflowY + css . overflowX ) ) {
118
+ break
119
+ }
120
+
121
+ // Check if the scrollable container is already overflowing
122
+ if (
123
+ scrollableParent . scrollHeight > scrollableParent . clientHeight ||
124
+ scrollableParent . scrollWidth > scrollableParent . clientWidth
125
+ ) {
117
126
break
118
127
}
119
128
120
129
scrollableParent = scrollableParent . parentElement
121
130
}
122
131
123
- // We crawled up the tree until the beginnging of the Portal, let's prevent the event.
132
+ // We crawled up the tree until the beginnging of the Portal, let's prevent the
133
+ // event if this is the case. If not, then we are in a container where we are
134
+ // allowed to scroll so we don't have to prevent the event.
124
135
if ( scrollableParent . dataset . headlessuiPortal === '' ) {
125
136
e . preventDefault ( )
126
137
}
127
138
}
128
139
129
- // We are not in an allowed contains , so let's prevent the event.
140
+ // We are not in an allowed container , so let's prevent the event.
130
141
else {
131
142
e . preventDefault ( )
132
143
}
0 commit comments