Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "Scroll lock" scrollbar width for Dialog component #1457

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve `FocusTrap` behaviour ([#1432](https://github.com/tailwindlabs/headlessui/pull/1432))
- Simplify `Popover` Tab logic by using sentinel nodes instead of keydown event interception ([#1440](https://github.com/tailwindlabs/headlessui/pull/1440))
- Ensure the `PopoverPanel` is clickable without closing the `Popover` ([#1443](https://github.com/tailwindlabs/headlessui/pull/1443))
- Improve "Scroll lock" scrollbar width for `Dialog` component ([#1457](https://github.com/tailwindlabs/headlessui/pull/1457))

## [Unreleased - @headlessui/react]

Expand All @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve `FocusTrap` behaviour ([#1432](https://github.com/tailwindlabs/headlessui/pull/1432))
- Simplify `Popover` Tab logic by using sentinel nodes instead of keydown event interception ([#1440](https://github.com/tailwindlabs/headlessui/pull/1440))
- Ensure the `Popover.Panel` is clickable without closing the `Popover` ([#1443](https://github.com/tailwindlabs/headlessui/pull/1443))
- Improve "Scroll lock" scrollbar width for `Dialog` component ([#1457](https://github.com/tailwindlabs/headlessui/pull/1457))

## [@headlessui/react@1.6.1] - 2022-05-03

Expand Down
10 changes: 7 additions & 3 deletions packages/@headlessui-react/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,14 @@ let DialogRoot = forwardRefWithAs(function Dialog<
let overflow = documentElement.style.overflow
let paddingRight = documentElement.style.paddingRight

let scrollbarWidth = ownerWindow.innerWidth - documentElement.clientWidth

let scrollbarWidthBefore = ownerWindow.innerWidth - documentElement.clientWidth
documentElement.style.overflow = 'hidden'
documentElement.style.paddingRight = `${scrollbarWidth}px`

if (scrollbarWidthBefore > 0) {
let scrollbarWidthAfter = documentElement.clientWidth - documentElement.offsetWidth
let scrollbarWidth = scrollbarWidthBefore - scrollbarWidthAfter
documentElement.style.paddingRight = `${scrollbarWidth}px`
}

return () => {
documentElement.style.overflow = overflow
Expand Down
10 changes: 7 additions & 3 deletions packages/@headlessui-vue/src/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ export let Dialog = defineComponent({
let overflow = documentElement.style.overflow
let paddingRight = documentElement.style.paddingRight

let scrollbarWidth = ownerWindow.innerWidth - documentElement.clientWidth

let scrollbarWidthBefore = ownerWindow.innerWidth - documentElement.clientWidth
documentElement.style.overflow = 'hidden'
documentElement.style.paddingRight = `${scrollbarWidth}px`

if (scrollbarWidthBefore > 0) {
let scrollbarWidthAfter = documentElement.clientWidth - documentElement.offsetWidth
let scrollbarWidth = scrollbarWidthBefore - scrollbarWidthAfter
documentElement.style.paddingRight = `${scrollbarWidth}px`
}

onInvalidate(() => {
documentElement.style.overflow = overflow
Expand Down