Skip to content

Commit

Permalink
allow horizontal scrolling when scroll locking (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait authored Dec 20, 2023
1 parent 9f0b19f commit 7a1940e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Allow horizontal scrolling when scroll locking ([bdf4f8e](https://github.com/tailwindlabs/headlessui/commit/bdf4f8e32358485dd9c437c0d631309250ee5624))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
if (inAllowedContainer(e.target as HTMLElement)) {
// We are in an allowed container, however on iOS the page can still scroll in
// certain scenarios...

let rootContainer = e.target
while (
rootContainer.parentElement &&
Expand All @@ -113,20 +112,32 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
// portal, its over.
scrollableParent.dataset.headlessuiPortal !== ''
) {
if (scrollableParent.scrollHeight > scrollableParent.clientHeight) {
// Verify that we are in a scrollable container (which may or may not overflow yet)
let css = window.getComputedStyle(scrollableParent)
if (/(auto|scroll)/.test(css.overflow + css.overflowY + css.overflowX)) {
break
}

// Check if the scrollable container is already overflowing
if (
scrollableParent.scrollHeight > scrollableParent.clientHeight ||
scrollableParent.scrollWidth > scrollableParent.clientWidth
) {
break
}

scrollableParent = scrollableParent.parentElement
}

// We crawled up the tree until the beginnging of the Portal, let's prevent the event.
// We crawled up the tree until the beginnging of the Portal, let's prevent the
// event if this is the case. If not, then we are in a container where we are
// allowed to scroll so we don't have to prevent the event.
if (scrollableParent.dataset.headlessuiPortal === '') {
e.preventDefault()
}
}

// We are not in an allowed contains, so let's prevent the event.
// We are not in an allowed container, so let's prevent the event.
else {
e.preventDefault()
}
Expand Down

1 comment on commit 7a1940e

@vercel
Copy link

@vercel vercel bot commented on 7a1940e Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-vue – ./packages/playground-vue

headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue-tailwindlabs.vercel.app
headlessui-vue.vercel.app

Please sign in to comment.