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

Don't scroll lock when transition isn't showing #2422

Merged
merged 3 commits into from
Apr 10, 2023
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
22 changes: 22 additions & 0 deletions packages/@headlessui-react/src/components/dialog/dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,28 @@ describe('Rendering', () => {
expect(document.documentElement.style.overflow).toBe('')
})
)

it(
'should not have a scroll lock when the transition marked as not shown',
suppressConsoleLogs(async () => {
function Example() {
return (
<Transition as={Fragment} show={false} unmount={false}>
<Dialog as="div" onClose={() => {}}>
<input type="text" />
</Dialog>
</Transition>
)
}

render(<Example />)

await nextFrame()

// The overflow should NOT be there
expect(document.documentElement.style.overflow).toBe('')
})
)
})

describe('Dialog.Overlay', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix focus styles showing up when using the mouse ([#2347](https://github.com/tailwindlabs/headlessui/pull/2347))
- Disable `ComboboxInput` when its `Combobox` is disabled ([#2375](https://github.com/tailwindlabs/headlessui/pull/2375))
- Add `FocusTrap` event listeners once document has loaded ([#2389](https://github.com/tailwindlabs/headlessui/pull/2389))
- Don't scroll-lock `<Dialog>` when wrapping transition isn't showing ([#2422](https://github.com/tailwindlabs/headlessui/pull/2422))

### Added

Expand Down
24 changes: 24 additions & 0 deletions packages/@headlessui-vue/src/components/dialog/dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,30 @@ describe('Rendering', () => {
expect(document.documentElement.style.overflow).toBe('')
})
)

it(
'should not have a scroll lock when the transition marked as not shown',
suppressConsoleLogs(async () => {
renderTemplate({
components: {
Dialog,
TransitionRoot,
},
template: `
<TransitionRoot as="template" :show="false" :unmount="false">
<Dialog as="div">
<input type="text" />
</Dialog>
</TransitionRoot>
`,
})

await nextFrame()

// The overflow should NOT be there
expect(document.documentElement.style.overflow).toBe('')
})
)
})

describe('DialogOverlay', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ export let TransitionChild = defineComponent({
}

let container = ref<HTMLElement | null>(null)
let state = ref(TreeStates.Visible)
let strategy = computed(() => (props.unmount ? RenderStrategy.Unmount : RenderStrategy.Hidden))

expose({ el: container, $el: container })

let { show, appear } = useTransitionContext()
let { register, unregister } = useParentNesting()

let state = ref(show.value ? TreeStates.Visible : TreeStates.Hidden)
let initial = { value: true }

let id = useId()
Expand Down Expand Up @@ -228,7 +228,7 @@ export let TransitionChild = defineComponent({
if (!id) return

// Make sure that we are visible
if (show && state.value !== TreeStates.Visible) {
if (show.value && state.value !== TreeStates.Visible) {
state.value = TreeStates.Visible
return
}
Expand Down