Md-menu closes after pressing md-tab inside

I built md-menuwith the md-tab-groupinside using Angular Material 2. Each one md-tabdisplays a different list. The behavior I expect to see is that the user can switch between tabs and md-menuto stay open.

The fact is that closing md-menueach time you click on one of the tabs.

 <img src="/assets/images/ic-notifications.png" [mdMenuTriggerFor]="appMenu"/> 

 <md-menu #appMenu="mdMenu"  [overlapTrigger]="false" yPosition="below" xPosition="before" class="notifications-dropdown">
  <md-tab-group >
   <md-tab label="My profile" id="personal">          
     <div class="row notification-row" *ngFor = "let notification of profile_notifications">
        ...
      </div>
   </md-tab>
   <md-tab label="Favorites " id="favorite-tab" >  
  ...
      </md-tab>
   </md-tab-group>
</md-menu>      

How can I prevent the closure md-menu?

+4
source share
1 answer

You need to stop the spread of the mouse. You can do it as follows:

<md-menu #appMenu="mdMenu" [overlapTrigger]="false" yPosition="below" xPosition="before" class="notifications-dropdown">
    <md-tab-group (click)="stopClickPropagate($event)">
        <md-tab label="My profile" id="personal"></md-tab>
        <md-tab label="Favorites " id="favorite-tab"></md-tab>
    </md-tab-group>
</md-menu>

and in component.ts file:

stopClickPropagate(event: any){
    event.stopPropagation();
    event.preventDefault();
}

- .

+3

Source: https://habr.com/ru/post/1684387/


All Articles