Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material2 How to open md-menu on mouseenter

I am using Material 2 to create a menu. I have a md-button trigger that opens a md-menu. I want the button to open on hover. I know that the Material Angular.io is still pretty new. I have googled the problem but I just come up with Angularjs results. Can anyone point me in the right direction?

Here is a sample of my html:

    <button md-button [mdMenuTriggerFor]="userMenu" class="nav-btn" ><i class="fa fa-user" aria-hidden="true" id="user-icon"></i> NAME</button>
    <md-menu #userMenu="mdMenu" xPosition="before" yPosition="below" [overlapTrigger]="false">
        <button md-menu-item class="nav-dropdown" [routerLink]="['/dashboard']">DASHBOARD</button>
        <button md-menu-item class="nav-dropdown">MY PROFILE</button>
        <button md-menu-item class="nav-dropdown">lOGOUT</button>
    </md-menu>
like image 588
Jason_Sunday Avatar asked Aug 02 '17 22:08

Jason_Sunday


1 Answers

You can do it by manually triggering the openMenu() method on mouseenter.

Example:

<button md-icon-button 
        [md-menu-trigger-for]="menu" 
        #menuTrigger="mdMenuTrigger" 
        (mouseenter)="menuTrigger.openMenu()"
        style="margin-right: 25px">
  <md-icon>more_vert</md-icon>Menu 1
</button>

<md-menu #menu="mdMenu">
  <button md-menu-item>
    <md-icon>dialpad</md-icon>
    <span>Redial</span>
  </button>
  <button md-menu-item disabled>
    <md-icon>voicemail</md-icon>
    <span>Check voicemail</span>
  </button>
  <button md-menu-item>
    <md-icon>notifications_off</md-icon>
    <span>Disable alerts</span>
  </button>
</md-menu>

Plunker demo

For your code, it would be:

<button md-button #menuTrigger="mdMenuTrigger" 
                  (mouseenter)="menuTrigger.openMenu()"
                  [mdMenuTriggerFor]="userMenu" 
                  class="nav-btn" >
  <i class="fa fa-user" aria-hidden="true" id="user-icon"></i> 
  NAME
</button>
like image 141
Nehal Avatar answered Nov 19 '22 05:11

Nehal