The angular material project provides menu component overview, API and example. I want to improve one automatically dropdown if mouse is over. So my changes are (as it described in material doc):
menu-overview-example.html
<button mat-button [matMenuTriggerFor]="menu" (mouseenter)="someMethod()">Menu</button>
<mat-menu #menu="matMenu">
<button mat-menu-item >User</button>
<button mat-menu-item >Cards</button>
<button mat-menu-item >About</button>
</mat-menu>
and correspond ts file is menu-overview-example.ts
:
import {Component, ViewChild} from '@angular/core';
import { MatMenuTrigger } from '@angular/material';
@Component({
selector: 'menu-overview-example',
templateUrl: 'menu-overview-example.html',
styleUrls: ['menu-overview-example.css'],
})
export class MenuOverviewExample {
@ViewChild(MatMenuTrigger) trigger: MatMenuTrigger;
someMethod() {
this.trigger.openMenu();
}
}
Question 1
Is it possible do not implement method in menu-overview-example.ts
to handle trigger, but provide correspond method call on menu-overview-example.html
? For example (I do not know correct instruction to get access to the event):
<button mat-button-touggle aria-label="Open menu with custom trigger"
[matMenuTriggerFor]="menu" (mouseenter)="#menu.openMenu()">
Question 2
If my mouse is over menu, it opens - seems good. But I've got side effect my first menu item gets grey color. Is it possible to handle correctly?
More details
The test project is accessible here.