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
[Bug]: Slot in PopoverButton #485
Comments
I'm facing exactly the same problem with I assume both |
I found a simple workaround with <MenuButton as="span">
<slot name="button">
<MyButton>{{ buttonText }}</MyButton>
</slot>
</MenuButton> However, it has some negative consequences. For example, the button is not focused after the menu is closed. But otherwise, it works pretty well. |
While this does work it still introduces an extra element into the page flow, which is not ideal in my case. |
As a workaround I put MenuButton inside trigger slot: <template>
<Menu>
<slot name="trigger">
<MenuButton as="template">
<button>Default trigger</button>
</MenuButton>
</slot>
<MenuItems>
<!-- ... -->
</MenuItems>
</Menu>
</template> So to add custom trigger I need to wrap it in headlessui's MenuButton component: <Dropdown :items="items">
<template #trigger>
<MenuButton as="template">
<MyButton>
Custom trigger via slot
</MyButton>
</MenuButton>
</template>
</Dropdown> That way I have no additional wrappers and correct aria-labels on custom button. |
Hey! Thank you for your bug report! This should be fixed by #1548, and will be available in the next release. You can already try it using |
What package within Headless UI are you using?
@headlessui/vue
What version of that package are you using?
v.1.1.1
What browser are you using?
Chrome
Reproduction repository
https://codesandbox.io/s/headlessuivue-menu-example-forked-268dv
Describe your issue
I was hoping to use the popover component as a wrapper for a type of menu where the trigger button can be anything but the rest of the popover is always the same, which led me to using a slot as the PopoverButton's child.
Since I want to keep the elements the same as before I tried rendering the button as a template, with the intention of the slot content being used instead.
However, as you can see from the code box example, rendering a PopoverButton as a Template doesn't work.
What's the recommended approach here? Maybe pass in the component as a prop, then use
:as="mycomponent"
on the PopoverButton?The text was updated successfully, but these errors were encountered: