I got menu that is being displayed on mouseenter
event of a button. All that in toolbar:
<mat-toolbar color="primary">
<button mat-button routerLink="/products" [matMenuTriggerFor]="menu1"
#matMenu1Trigger="matMenuTrigger"
(mouseenter)="matMenu1Trigger.openMenu()">Menu1
</button>
<mat-menu #menu1="matMenu">
<div (mouseleave)="matMenu1Trigger.closeMenu()">
<button mat-menu-item>Item 1</button>
</div>
</mat-menu>
</mat-toolbar>
The menu is closed when mouseleave
event of surrounding span, so far so good.
Now I want to close the menu on mouseleave
of the triggering button as well by adding
(mouseleave)="matMenu1Trigger.closeMenu()"
When I do this and move mouse over this button, menu starts to flicker, like its being opened/closed every few miliseconds.
Why is that and how to hide the menu when mouse leaves the button?
https://stackblitz.com/edit/angular-kd8bue
Edit: After some googling I found out this behavior is caused by an overlay being displayed when the menu is opened as described here How to open mat-menu on a single click and close other opened menu if there is any?. Not sure if what I would like to achieve is even possible because of the overlay...