-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Using custom component as dropdown trigger #21
Comments
By default we use a However, the actual DOM ref is not applied correctly. I have to come back to this issue because I am not 100% sure why this is happening (or rather not happening). |
Hey @RobinMalfait - I was just wondering if there was any update on this issue? I'm currently just wrapping the component in a Happy to provide any more details if needed 😄 |
Hey! Sorry for the very long wait. I know that Vue has "special" behaviour implemented for That said, here is an alternative implementation that might work for you out of the box: https://codesandbox.io/s/headlessuivue-menu-example-forked-vvzft?file=/src/App.vue |
Hey, I have a similar error but I am not using the slot to render the custom button, but the Example code for using a custom component
<template>
<Menu>
<MenuButton ref="reference" :as="as">
Demo Button
</MenuButton>
<div ref="popper" class="w-56">
<!-- menu content -->
</div>
</Menu>
</template>
<script lang="ts">
import { DemoButton } from 'my-ui-lib'
import { Menu, MenuButton } from "@headlessui/vue";
export default defineComponent({
components: {
Menu,
MenuButton,
},
setup() {
const reference = ref(null) as Ref<null | { el: { $el: HTMLElement } }>;
const popper = ref(null) as Ref<null | HTMLElement>;
onMounted(() => {
watchEffect((onInvalidate) => {
const popperEl = popper.value;
const referenceEl = reference.value?.el?.$el;
if (!(referenceEl instanceof HTMLElement)) return;
if (!(popperEl instanceof HTMLElement)) return;
const { destroy } = createPopper(referenceEl, popperEl, {
placement: "bottom",
strategy: "fixed",
modifiers: [{ name: "offset", options: { offset: [0, 10] } }],
});
onInvalidate(destroy);
});
});
return {
reference,
popper,
as: DemoButton,
};
},
});
</script> While the above approach seems to work I got two errors in the console.
and
But the While digging in the debugger I think I found the reason for the error. Because in the above case, the button ref is not an instance of When changing this line, the error about accessing id disappears, but then it breaks for instances where no custom component is used as the button. So probably there needs to be some kind of check what kind of reference I could not find out what the reason for the second error is, but is seems to also be connected to using a custom component. |
I encountered another error which also seems to be caused by
which happens in for example in this line I think this also explains the not working focus described by @elilabes |
There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21
* add small dom utility to resolve the dom node from a ref * use dom() to resolve underlying DOM node There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21 * update changelog
Hey! This should be fixed, and will be available in the next release. Fixed it in #249, thanks for the extra pointers @a47ae. Here is an example with the new (dev) version: https://codesandbox.io/s/headlessuivue-menu-example-forked-vvzft?file=/src/App.vue |
* add small dom utility to resolve the dom node from a ref * use dom() to resolve underlying DOM node There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21 * update changelog
* add small dom utility to resolve the dom node from a ref * use dom() to resolve underlying DOM node There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21 * update changelog
* add small dom utility to resolve the dom node from a ref * use dom() to resolve underlying DOM node There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21 * update changelog
* add small dom utility to resolve the dom node from a ref * use dom() to resolve underlying DOM node There is probably a better way to do this, the idea is that we apply a ref to the component. However by default for html components `yourRef.value` will be the underlying DOM node. However if you pass the ref to another component, the actual DOM node will be located at `yourRef.value.$el`. Fixes: #21 * update changelog
I've started having a play around with this today and it's awesome! I ran into an issue though and I'm not sure if it is because I am doing something wrong / not using it as intended or if there is a bug.
I would like to use a custom button component to trigger the dropdown like so,
<MenuButton as="template"><MyCustomButton>Options</MyCustomButton></MenuButton>
however when I open the dropdown, I get the following error:
[Vue warn]: Property "id" was accessed during render but is not defined on instance.
Uncaught TypeError: _buttonRef$value.contains is not a function
Im using the latest version of Vue 3, 0.1.3 of Headless UI.
The text was updated successfully, but these errors were encountered: