Skip to content
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

dropdown not hide after click if use "to" prop for item #899

Closed
aloky opened this issue Nov 1, 2023 · 4 comments
Closed

dropdown not hide after click if use "to" prop for item #899

aloky opened this issue Nov 1, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@aloky
Copy link

aloky commented Nov 1, 2023

Environment

Nuxt 3.7.4 with Nitro 2.7.2

Version

v2.10.0

Reproduction

Not have

Description

Dropdown not hide after click, if use in header dropdown with links dropdown not hide after click

Additional context

No response

Logs

No response

@aloky aloky added the bug Something isn't working label Nov 1, 2023
@aloky aloky changed the title dropdown not hide after click dropdown not hide after click if use "to" prop for item Nov 1, 2023
@flozdra
Copy link
Contributor

flozdra commented Nov 3, 2023

Hi,

I have the same issue with reproduction here: https://stackblitz.com/edit/nuxt-ui-eomajj?file=app.vue

I'm not sure where the issue comes from. As soon as the NuxtLink (or RouterLink) is in the HMenuItem, the @click event is not triggered :

<NuxtLink to="/" @click="console.log('click')">
  Trigger the click event
</NuxtLink>

<HMenuItem>
  <NuxtLink to="/" @click="console.log('click')">
    Doesn't trigger the click event
  </NuxtLink>
</HMenuItem>

I think this is related to this issue: tailwindlabs/headlessui#143 (comment)

The only workaround I found is to wrap the HMenuItem in NuxtLink with the custom prop, and manually close the dropdown, as suggested in the previous issue.

<NuxtLink v-slot="{ href, navigate }" to="/" custom>
    <HMenuItem v-slot="{ close }">
        <a :href="href" @click.prevent="[navigate(), close()]">...</a>
    </HMenuItem>
</NuxtLink>

@narr07
Copy link

narr07 commented Nov 14, 2023

same issue, dropdown not closed after click menu in mobile nav menu. what the solution for this?

@flozdra
Copy link
Contributor

flozdra commented Nov 14, 2023

@narr07 For now as a workaround I use the function to navigate: click : () => navigateTo('/profile')

Copy link
Member

@flozdra Thanks! I've implemented your suggestion and it seems to finally fix the issue 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants