Components: matMenuTriggerFor should never propagate

Created on 11 Jan 2018  路  4Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature Request

What is the expected behavior?

Click events should not propagate with matMenuTriggerFor.

What is the current behavior?

Click events do propagate when a matMenuTriggerFor is invoked.

What are the steps to reproduce?

<a (click)="dontOpenMeWhenAMenuIsClicked()"> .... <button matMenuTriggerFor="...."></button> </a>

And yes this is surely not perfect HTML but there are use cases, like for example when you have table row that expands on click but the UX designer wants a menu button in there as well.

What is the use-case or motivation for changing an existing behavior?

When clicking to open a menu that's the only desired behavior.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

all

Is there anything else we should know?

Most helpful comment

FWIW this should do the trick

<button (click)="$event.stopPropagation()" mat-button [matMenuTriggerFor]="menu">Menu</button>

All 4 comments

I feel like doing it for all menu triggers is way too opinionated and it could break existing users. Closing since it's trivial to workaround on the consuming side.

FWIW this should do the trick

<button (click)="$event.stopPropagation()" mat-button [matMenuTriggerFor]="menu">Menu</button>

@crisbeto I have similar functionality but I am not sure if I experience the same error.
In my case I have a image that I want to view or edit so I open a menu with 2 options clicking on the image
Whenever I use the mouse it works well but when I add (keydown) ="...'" to use the keyboard - I get a new mose event from somewhere ? So even using event.stopPropagation() inside openMenuKeyboard(...) doesn't help.

Simplified version of the case is here: https://stackblitz.com/edit/angular-jov1k4

Do you think should I fill a new issue or is the same?

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings