Md-menu closes after clicking md-tab inside

我只是一个虾纸丫 提交于 2020-02-21 13:46:45

问题


I built an md-menu with an md-tab-group inside, using Angular Material 2. On each md-tab I display a different list. The behavior I'm expecting to see is that the user to be able to switch between tabs and the md-menu to stay opened.

The thing is that the md-menu closing on every 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 md-menu from closing?


回答1:


You need to stop the mouse click propagation. You can do it like this:

<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 your component.ts file:

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

Link to Plunker Demo.



来源:https://stackoverflow.com/questions/45864030/md-menu-closes-after-clicking-md-tab-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!