@@ -95,30 +95,26 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
9595 // Check if we are scrolling inside any of the allowed containers, if not let's cancel the event!
9696 if ( e . target instanceof HTMLElement ) {
9797 if ( inAllowedContainer ( e . target as HTMLElement ) ) {
98- // We are in an allowed container, however on iOS the page can still scroll in
99- // certain scenarios...
100- let rootContainer = e . target
101- while (
102- rootContainer . parentElement &&
103- inAllowedContainer ( rootContainer . parentElement )
104- ) {
105- rootContainer = rootContainer . parentElement !
106- }
107-
108- let scrollableParent = rootContainer
98+ // Even if we are in an allowed container, on iOS the main page can still scroll, we
99+ // have to make sure that we `event.preventDefault()` this event to prevent that.
100+ //
101+ // However, if we happen to scroll on an element that is overflowing, or any of its
102+ // parents are overflowing, then we should not call `event.preventDefault()` because
103+ // otherwise we are preventing the user from scrolling inside that container which
104+ // is not what we want.
105+ let scrollableParent = e . target
109106 while (
110107 scrollableParent . parentElement &&
111- // Assumption that we are always used in a Headless UI Portal. Once we reach the
112- // portal, its over .
108+ // Assumption: We are always used in a Headless UI Portal. Once we reach the
109+ // portal itself, we can stop crawling up the tree .
113110 scrollableParent . dataset . headlessuiPortal !== ''
114111 ) {
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
112+ // Check if the scrollable container is overflowing or not.
113+ //
114+ // NOTE: we could check the `overflow`, `overflow-y` and `overflow-x` properties
115+ // but when there is no overflow happening then the `overscrollBehavior` doesn't
116+ // seem to work and the main page will still scroll. So instead we check if the
117+ // scrollable container is overflowing or not and use that heuristic instead.
122118 if (
123119 scrollableParent . scrollHeight > scrollableParent . clientHeight ||
124120 scrollableParent . scrollWidth > scrollableParent . clientWidth
0 commit comments