Close drop down on item selection

Forum rules
Please note that response time for technical support is within 3-5 business days.
Post Reply
ricombnation
Posts: 24
Joined: 11 Jan 2022, 10:54

02 Mar 2022, 15:55

I'm using the following PrimeBlock code for a user menu dropdown:

Code: Select all

<ul v-if="username"
    class="list-none p-0 m-0 flex lg:align-items-center select-none flex-column lg:flex-row border-top-1 border-bottom-1 lg:border-top-none lg:border-bottom-none border-gray-300 bg-white">
    <li class="lg:relative">
        <a class="flex px-6 p-3 lg:px-3 lg:py-2 align-items-center text-600 hover:text-900 font-medium border-round cursor-pointer transition-colors transition-duration-150"
           v-styleclass="{ selector: '@next', enterClass: 'hidden', enterActiveClass: 'scalein', leaveToClass: 'hidden', leaveActiveClass: 'fadeout', hideOnOutsideClick: true }">
            <span v-text="username" class="text-sm"/>
            <i class="pi pi-angle-down ml-auto lg:ml-2"></i>
        </a>
        <ul class="list-none py-3 px-6 m-0 lg:px-0 lg:py-0 border-round shadow-0 lg:shadow-2 lg:border-1 border-50 lg:absolute surface-overlay hidden origin-top w-full lg:w-15rem cursor-pointer">
            <li v-for="entry in userEntries">
                <Link :href="entry.url"
                      v-text="entry.label"
                      class="flex no-underline p-3 align-items-center text-600 hover:text-900 hover:surface-100 transition-colors transition-duration-150">
                </Link>
            </li>
        </ul>
    </li>
</ul> 
Unfortunately, when a user clicks on a Link (menu item) the dropdown stays open. Is there an easy way to close the dropdown, when the user clicks on a menu item?

tugce.kucukoglu
Posts: 560
Joined: 23 Oct 2020, 09:28

03 Mar 2022, 10:56

It's a just quick workaround:

Code: Select all

<ul :class="['list-none ... ', { 'hidden': showMenu}]">
   <li>
       <a @click="onClick" >

Code: Select all

onClick() {
   this.showMenu = !this.showMenu;
}

ricombnation
Posts: 24
Joined: 11 Jan 2022, 10:54

04 Mar 2022, 13:00

Thanks ... simple and effective.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

08 Apr 2022, 12:37

Thanks @tugce ;)

Post Reply

Return to “PrimeBlocks for PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests