Adding panelClass to mat-menu does nothing
See original GitHub issueBug:
Adding panelClass to mat-menu does nothing. The problem is that material menu gets rendered using cdk-overlay-pane
, which is outside of the component and imposible to style without using ::ng-deep
, which interferes with other components using overlay panel.
What is the expected behavior?
Accoring to documentation:
@Input('class')
panelClass: string
This method takes classes set on the host mat-menu element and applies them on the menu template that displays in the overlay container. Otherwise, it's difficult to style the containing menu from outside the component.
Example of non-working code:
<div class="container" [matMenuTriggerFor]="avatarMenu" matTooltip="{{account?.tenantCode}}">
<span [ngClass]="serverIsReachable ? 'avatar' : 'offline'"></span>
<div class="account" *ngIf="serverIsReachable">
<span class="name">{{account?.firstName + ' ' + account?.lastName}}</span>
<span class="email">{{account?.email}}</span>
</div>
<div class="account" *ngIf="!serverIsReachable">
<span>{{'server-is-unreachable' | translate}}</span>
</div>
</div>
<mat-menu #avatarMenu="matMenu" yPosition="below" panelClass="custom" [overlapTrigger]="false">
<div class="settings">
<label>{{'language'|translate}}</label>
<div class="languages">
<span [ngClass]="{ 'sel': trans.currentLang === 'sr' }" (click)="setLang('sr')">SRP</span>
<span [ngClass]="{ 'sel': trans.currentLang === 'en' }" (click)="setLang('en')">ENG</span>
</div>
</div>
<button mat-menu-item class="logout" (click)="logout()">
<mat-icon>power_settings_new</mat-icon>
<span>{{'logout'|translate}}</span>
</button>
</mat-menu>
What is the current behavior?
Inspecting HTML tree, no classes were applied to any element, even though panelClass
property was set on mat-menu component.
What are the steps to reproduce?
Check the info given above
What is the use-case or motivation for changing an existing behavior?
I want to set position and width of overlay element rendering menu contents.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Linux Mint 18.3 Angular 5.2.8 Angular Material 5.2.3 Typescript 2.7.1
Is there anything else we should know?
I know that people reported similar issue earlier, but there wasn’t any viable explanation or solution given to it.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:26 (2 by maintainers)
Top Results From Across the Web
How to add class on mat-menu overlay in Angular 5?
Actually, I want to apply a class on parent cdk overlay because in responsive it is not showing perfectly. – Jimit. Mar 8,...
Read more >Menu | Angular Material
panelClass : string. This method takes classes set on the host mat-menu element and applies them on the menu template that displays in...
Read more >how can i apply custom class next to cdk-overlay-pane for ...
i tried to apply custom class on using class and panelClass attribute. ... do not work in Internet Explorer prior to v10, though...
Read more >Panelclass Issue
MIT-style license that can be. * found in the LICENSE file at https:// angular.io/license. */. import. Enter to Rename, Shift+Enter to Preview.
Read more >angular material snackbar panelclass
... Adding panelClass to mat-menu does nothing. UI component infrastructure and Material Design components for mobile and desktop Angular web applications.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try to use with
using the “class” input does the job, but this is still a bug, or at least the API documentation is misleading. This bug should not have been closed imho.