primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Menu | itemClick requires double click in popup mode if items generated by function

Open roman-bychkov opened this issue 3 years ago • 21 comments

Describe the bug

Component: Menu inside a table row. User should click twice on menu action to reach an action.

Environment

  1. Click on Menu in table row
  2. Click on Menu action once (will nothing happen)
  3. Click on Menu action again - Action will executed

Reproducer

https://stackblitz.com/edit/8numcb-pnb4qf?file=src%2Fapp%2Fdemo%2Ftable-basic-demo.html

Angular version

16.2.0

PrimeNG version

16.5.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v18.12.1

Browser(s)

No response

Steps to reproduce the behavior

  1. Click on Menu in table row
  2. Click on Menu action (nothing happens)
  3. Click on Menu action again - Action will executed

Expected behavior

When user click first time on menu action. Action should be execute.

roman-bychkov avatar Oct 20 '23 10:10 roman-bychkov

any suggestions?

roman-bychkov avatar Nov 09 '23 08:11 roman-bychkov

In fiddling with this trying to find a workaround, I noticed that the bug goes away if you set an invalid appendTo, but not if you leave off appendTo. In comparing the menu objects after toggling, I noticed the ones that don't work (those without invalid appendTo), have a documentClickListener defined that points to a function called removeEventListener. Whereas the menu with the invalid appendTo does not have this. Also after the MenuItem command is executed, I notice none of the menus have this documentClickListener set.

Stackblitz example: https://stackblitz.com/edit/8numcb-2leua7

I'm not sure how to formulate a workaround based on this, or if it has anything to do with the issue. I tried removing the documentClickListener in the toggle event to see if that works without luck, but I'm not sure I'm doing so correctly. Perhaps this documentClickListener needing to be consumed is what the first/ineffective click on a menu item is accomplishing. After which point the second click is then able to work?

dnordahl1 avatar Nov 28 '23 19:11 dnordahl1

Hi,

Thanks a lot for reporting the issue, great catch!

cetincakiroglu avatar Dec 27 '23 06:12 cetincakiroglu

Hi,

After investigating the matter, I've discovered an interesting correlation with the tabindex attribute within the <ul></ul> element. As part of our accessibility enhancements, we've incorporated a tabindex value along with focus and blur events to facilitate menu accessibility. However, this implementation seems to trigger the issue specifically when options are provided by a function. I tested your code in versions v14, v15, and v16 (pre-accessibility) and observed that the issue did not occur previously because the menu lacked tabindex input and support for focus and blur. Introducing a tabindex to the top ul element caused the issue, necessitating a double click. At present, the most effective solution seems to be setting tabindex to undefined. I've added a method to set tabindex to 'undefined'.

cetincakiroglu avatar Dec 28 '23 14:12 cetincakiroglu

@cetincakiroglu Do you know if this fix will be added to a version 16 release after being verified in 17?

In the stackblitz example I tried setting tabindex to undefined, null, and a value in both the menuItem html attributes and the model attributes, and it didn't seem to provide a workaround.

dnordahl1 avatar Dec 28 '23 17:12 dnordahl1

Try this

<p-menu [tabindex]="undefined"></p-menu>

cetincakiroglu avatar Dec 28 '23 17:12 cetincakiroglu

@cetincakiroglu That doesn't seem to work either:

https://stackblitz.com/edit/8numcb-56sipg

dnordahl1 avatar Dec 28 '23 17:12 dnordahl1

Please see the example: https://stackblitz.com/edit/8numcb-fyvbtn?file=src%2Fapp%2Fdemo%2Ftable-basic-demo.html

cetincakiroglu avatar Dec 28 '23 19:12 cetincakiroglu

@cetincakiroglu I'm hoping for a work around for version 16 so that we're able to be on an LTS release.

dnordahl1 avatar Dec 28 '23 19:12 dnordahl1

@dnordahl1 I have implemented this workaround:

https://stackblitz.com/edit/8numcb-tc1ytv?file=src%2Fapp%2Fdemo%2Ftable-basic-demo.html,src%2Fapp%2Fdemo%2Ftable-basic-demo.ts

Hope this helps someone :)

IvanNovikov-mobdev avatar Jan 11 '24 13:01 IvanNovikov-mobdev

@IvanNovikov-mobdev Excellent.. I'm very grateful for you sharing this!

dnordahl1 avatar Jan 12 '24 18:01 dnordahl1

@cetincakiroglu This is still an issue in 17.9.0 [tabindex]="undefined" didn't help.

dorthrithil avatar Apr 01 '24 14:04 dorthrithil

@cetincakiroglu This is still an issue in 17.9.0 [tabindex]="undefined" didn't help.

Hi,

Thanks for letting us know, we'll check before 17.13.0 release.

cetincakiroglu avatar Apr 01 '24 14:04 cetincakiroglu

Is it known if this is fixed in 17.18.4 before we upgrade to it? We're been stuck on 15 because we can't afford to introduce this issue.

clairebones avatar Jul 16 '24 09:07 clairebones

The workaround [tabindex]="undefined" works for me using version 17.18.9

liefra avatar Aug 18 '24 04:08 liefra

Hello,

For some reason i am still facing the problem with 17.18.9 and 17.18.10

<div class="card flex justify-content-center">
  <p-menu #menu
          [tabindex]="undefined" styleClass="z-2" [model]="getMenuItemsForItem(item)" [popup]="true" appendTo="body">
    <ng-template pTemplate="item" let-mitem>
      @if (mitem.route) {
        <a [routerLink]="mitem.route" class="p-menuitem-link">
          <span [class]="mitem.icon"></span>{{mitem.route+''+item.id}}
          <span class="ml-2">{{ mitem.label }}</span>
        </a>
      } @else {
        <a class="p-menuitem-link">
          <span [class]="mitem.icon"></span>
          <span class="ml-2">{{ mitem.label }}</span>
        </a>
      }
    </ng-template>
  </p-menu>
  <p-button [rounded]="true" [outlined]="true" (onClick)="menu.toggle($event)" icon="pi pi-ellipsis-v"/>
</div>

with this in ts

getMenuItemsForItem(item: Survey): MenuItem[] {
    return [
      {
        label: 'Options',
        items: [
          {
            label: 'Edit',
            icon: 'pi pi-file-edit',
            route: '/survey/add/'+item.id,
          },
          {
            label: 'Manage answers',
            icon: 'pi pi-chart-bar',
            route: '/participation/survey/'+item.id,
          },
          {separator: true},
          {
            label: 'Delete',
            icon: 'pi pi-trash',
            style: {'color': 'red'},
            command: () => {
              this.deleteCl(item.id)
            }
          }
        ]
      }
    ]

Spiff77 avatar Sep 23 '24 09:09 Spiff77

The issue is present in v.17.18. I have set [tabindex]="undefined" and have worked for me. In my case, i have to override p-button for button.

AlbaSS18 avatar Sep 30 '24 08:09 AlbaSS18

The issue is present in v.17.18. I have set [tabindex]="undefined" and have worked for me. In my case, i have to override p-button for button.

thank you so much, works with me

devmuzaky avatar Dec 13 '24 17:12 devmuzaky

I found another problem when trying to use the menu on a Dialog. Here's the reproduction https://stackblitz.com/edit/japvvq7n-chk2yd6z?embed=1&file=src%2Fapp%2Fdialog-basic-demo.html In this case, using tabIndex="undefined" isn't working

Is there any update about this problem?

s-torrisi avatar Jan 20 '25 15:01 s-torrisi

This is still an issue in 19.0.5.

Only @IvanNovikov-mobdev's workaround fixed it

Marius-Ar avatar Feb 03 '25 20:02 Marius-Ar