Berndhura / LKS_web

0 stars 0 forks source link

hover over menu item -> new menu #1

Open Berndhura opened 4 years ago

Berndhura commented 4 years ago

https://stackoverflow.com/questions/53618333/how-to-open-and-close-angular-mat-menu-on-hover

<ng-container *ngFor="let menuItem of modulesList">

<ng-container *ngIf="!menuItem.children">
    <a class="nav-link">
        <span class="icon fa" [ngClass]="menuItem.icon"></span>
  <span class="text-holder">{{menuItem.label}}</span>
</a>

<ng-container *ngIf="menuItem.children.length > 0"> <button #button mat-button [matMenuTriggerFor]="levelOne" #levelOneTrigger="matMenuTrigger" (mouseenter)="buttonEnter(levelOneTrigger)" (mouseleave)="buttonLeave(levelOneTrigger, button)" style="z-index:1050"> <span class="icon fa" [ngClass]="menuItem.icon"> {{menuItem.label}}

<mat-menu #levelOne="matMenu" direction="down" yPosition="below">
  <span (mouseenter)="menuenter()" (mouseleave)="menuLeave(levelOneTrigger, button)">
  <ng-container *ngFor="let childL1 of menuItem.children">
    <li class="p-0" *ngIf="!childL1.children" mat-menu-item>
      <a class="nav-link">{{childL1.label}}
        <i *ngIf="childL1.icon" [ngClass]="childL1.icon"></i>
      </a>
    </li>
    <ng-container *ngIf="childL1.children && childL1.children.length > 0">
      <li mat-menu-item #levelTwoTrigger="matMenuTrigger" [matMenuTriggerFor]="levelTwo">
        <span class="icon fa" [ngClass]="childL1.icon"></span>
        <span>{{childL1.label}}</span>
      </li>

      <mat-menu #levelTwo="matMenu">
        <span (mouseenter)="menu2enter()" (mouseleave)="menu2Leave(levelOneTrigger,levelTwoTrigger, button)">
        <ng-container *ngFor="let childL2 of childL1.children">
          <li class="p-0" mat-menu-item>
            <a class="nav-link">{{childL2.label}}
              <i *ngIf="childL2.icon" [ngClass]="childL2.icon"></i>
            </a>
          </li>
        </ng-container>
        </span>
      </mat-menu>
    </ng-container>
  </ng-container>
  </span>
</mat-menu>

Berndhura commented 4 years ago

import { Component, Renderer2 } from '@angular/core'; import { ModulesList } from './menu';

/**