Skip to content

Commit 7a1940e

Browse files
authored
allow horizontal scrolling when scroll locking (#2889)
1 parent 9f0b19f commit 7a1940e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Allow horizontal scrolling when scroll locking ([bdf4f8e](https://github.com/tailwindlabs/headlessui/commit/bdf4f8e32358485dd9c437c0d631309250ee5624))
1113

1214
## [2.0.0-alpha.1] - 2023-12-20
1315

packages/@headlessui-react/src/hooks/document-overflow/handle-ios-locking.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
9797
if (inAllowedContainer(e.target as HTMLElement)) {
9898
// We are in an allowed container, however on iOS the page can still scroll in
9999
// certain scenarios...
100-
101100
let rootContainer = e.target
102101
while (
103102
rootContainer.parentElement &&
@@ -113,20 +112,32 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
113112
// portal, its over.
114113
scrollableParent.dataset.headlessuiPortal !== ''
115114
) {
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 (/(auto|scroll)/.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+
) {
117126
break
118127
}
119128

120129
scrollableParent = scrollableParent.parentElement
121130
}
122131

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.
124135
if (scrollableParent.dataset.headlessuiPortal === '') {
125136
e.preventDefault()
126137
}
127138
}
128139

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.
130141
else {
131142
e.preventDefault()
132143
}

0 commit comments

Comments
 (0)