Skip to content

Commit

Permalink
use a simpler position: fixed approach to prevent scroll locking
Browse files Browse the repository at this point in the history
This isn't super ideal, but just preventing the default behavior on the
entire document while `touchmove`-ing isn't ideal either because then
you can't scroll inside the dialog or on the backdrop if your dialog
panel is larger than the viewport.

Again, this is not 100% correct, but it is better because you will be
able to scroll the dialog, and not the body.
  • Loading branch information
RobinMalfait committed Sep 7, 2022
1 parent d2a0bdb commit 7b1a6d5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/@headlessui-react/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,10 @@ function useScrollLock(ownerDocument: Document | null, enabled: boolean) {
}

if (isIOS()) {
d.addEventListener(
ownerDocument,
'touchmove',
(e) => {
e.preventDefault()
},
{ passive: false }
)

let scrollPosition = window.pageYOffset
style(documentElement, 'position', 'fixed')
style(documentElement, 'marginTop', `-${scrollPosition}px`)
style(documentElement, 'width', `100%`)
d.add(() => window.scrollTo(0, scrollPosition))
}

Expand Down

0 comments on commit 7b1a6d5

Please sign in to comment.