Skip to content

Commit

Permalink
Don't overwrite user-defined template refs when rendering (#2720)
Browse files Browse the repository at this point in the history
* Merge vnode refs when rendering

In some cases if we used our own ref (we do this in `<TransitionRoot>` for instance) and rendered slot children we would wipe out  user-specified refs. So we set a flag when calling `cloneVNode` to merge our refs and any user-specified refs.

* Update changelog
  • Loading branch information
thecrypticace authored Aug 30, 2023
1 parent c92757d commit 5a1e2e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for `role="alertdialog"` to `<Dialog>` component ([#2709](https://github.com/tailwindlabs/headlessui/pull/2709))
- Ensure blurring the `ComboboxInput` component closes the `Combobox` ([#2712](https://github.com/tailwindlabs/headlessui/pull/2712))
- Allow `<button>` to be in nested components in `<PopoverButton>` ([#2715](https://github.com/tailwindlabs/headlessui/pull/2715))
- Don't overwrite user-defined template refs when rendering ([#2720](https://github.com/tailwindlabs/headlessui/pull/2720))

## [1.7.16] - 2023-08-17

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

it(
'should not have a scroll lock when the transition marked as not shown',
suppressConsoleLogs(async () => {
let dialogRef = ref(null)

renderTemplate({
components: {
Dialog,
TransitionRoot,
},
template: `
<button @click="show = !show">toggle</button>
<div id="output">{{ hasRef ? "Yes" : "No" }}</div>
<TransitionRoot as="template" :show="show">
<Dialog as="div" ref="dialogRef">
<input type="text" />
</Dialog>
</TransitionRoot>
`,
setup() {
let show = ref(false)

return {
show,
dialogRef,
}
},
})

expect(dialogRef.value).toBeNull()

await click(getByText('toggle'))
await nextFrame()

expect(dialogRef.value).not.toBeNull()

await click(getByText('toggle'))
await nextFrame()

expect(dialogRef.value).toBeNull()
})
)
})

describe('DialogOverlay', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function _render({
}

let mergedProps = mergeProps(firstChild.props ?? {}, incomingProps)
let cloned = cloneVNode(firstChild, mergedProps)
let cloned = cloneVNode(firstChild, mergedProps, true)
// Explicitly override props starting with `on`. This is for event handlers, but there are
// scenario's where we set them to `undefined` explicitly (when `aria-disabled="true"` is
// happening instead of `disabled`). But cloneVNode doesn't like overriding `onXXX` props so
Expand Down

2 comments on commit 5a1e2e4

@vercel
Copy link

@vercel vercel bot commented on 5a1e2e4 Aug 30, 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-tailwindlabs.vercel.app
headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5a1e2e4 Aug 30, 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-react – ./packages/playground-react

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

Please sign in to comment.