question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Vue warning when using custom SFC component in MenuButton as prop

See original GitHub issue

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

1.7.2

What browser are you using?

Chrome

Reproduction URL

n/a, I can create one in a codesandbox soon.

Describe your issue

I am using the dropdown menu component from HeadlessUI.

I have a custom button component (see below) that uses the <component> utility in Vue to switch between a link, button or span depending on whether it has href prop, click event or disabled prop.

Btn.vue

<template>
  <component
    :is="
      isDisabled && ($attrs.to || $attrs.href)
        ? 'span' : $attrs.to
        ? 'RouterLink' : $attrs.href
        ? 'a' : 'button'
    "
  >
    <slot />
  </component>
</template>  

I want to use this <Btn> in the :as prop on the <MenuButton> component.

  <Menu v-slot="slotProps" as="div" class="relative">
    <MenuButton
      :as="Btn"
      :variant="buttonVariant"
      :size="buttonSize"
    >
      <slot name="icon" v-bind="slotProps">
        <EllipsisVerticalIcon class="h-6 w-6" />
      </slot>
    </MenuButton>

However, I get the following warning

image

[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance. 
  at <Btn disabled=false ref=Ref< Proxy > id="headlessui-menu-button-51"  ... > 
  at <MenuButton as= Object variant="primary" size="md"  ... > 
  at <Menu as="div" class="relative" > 
  at <DropdownMenu menu-class="right-0" > 
  at <AutoScroll class="grow p-5" > 
  at <Edit id="94d20d55-e295-4781-af66-24fb5bf11f4b" onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< Proxy >  ... > 
  at <RouterView> 
  at <App>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
thecrypticacecommented, Oct 10, 2022

This was an issue on our part. Basically, we call the default slot ourselves to get the children vnodes and pass that to the createVNode function (usually called h). However, for components, they expect children in many cases to be an object w/ slot functions. Good news is we can do this even for element VNodes. I confirmed this because this is what <component> essentially ends up compiling to + doing when passing a type of div for instance.

Thanks for the report! This was merged in #1915 and will be available in our insiders build in a few minutes: npm install @headlessui/vue@insiders

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reuse a SFC Vue component instance in different ...
There are two ways to do this-. Globally import the component in the main.js file and use on any page freely. i.e.-. import...
Read more >
Props | Vue.js
Components can specify requirements for their props, such as the types you've already seen. If a requirement is not met, Vue will warn...
Read more >
Menu (Dropdown) - Headless UI
Each component exposes information about its current state via slot props that you can use to conditionally apply different styles or render different...
Read more >
Menu component - Vuetify
Vuetify is a Material Design component framework for Vue.js. ... placed absolutely on top of the activator element using the absolute prop.
Read more >
Vue.js 3 Component Events Tutorial - KoderHQ
How to listen for emitted events on a parent component; How to send data with an event; How to validate an emitted event;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found