Don't scroll lock when transition isn't showing (#2422)
* Add tests * Make transition initial state based on computed `show` prop * Update changelog
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -193,7 +193,6 @@ 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 })
|
||||
@@ -201,6 +200,7 @@ export let TransitionChild = defineComponent({
|
||||
let { show, appear } = useTransitionContext()
|
||||
let { register, unregister } = useParentNesting()
|
||||
|
||||
let state = ref(show.value ? TreeStates.Visible : TreeStates.Hidden)
|
||||
let initial = { value: true }
|
||||
|
||||
let id = useId()
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user