Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the width of the mat-menu-item?

<div fxHide fxHide.xs="false" fxHide.md="true">
  <button mat-icon-button [matMenuTriggerFor]="menu" class="my-menu">
    <mat-icon>more_vert</mat-icon>
  </button>
  <mat-menu #menu="matMenu">
    <button mat-menu-item *ngFor="let menu of repoService.toolbarMenu" class="mr-4" (click)="repoService.onToolbarClick(menu)"
    class="notifications-dropdown">

      <mat-icon *ngIf="menu.icon" aria-label="menu.key" class="mr-4">{{menu.icon}}</mat-icon>
      <span class="notification-row">{{menu.displayKey | translate}}</span>

    </button>
  </mat-menu>

Css File

.mat-menu-panel.notifications-dropdown {
      max-width:none;
      width: 100vw; 
      margin-left: -8px;
      margin-top: 24px;
      overflow: visible;
  }
  
  .notification-row{
      width: 424px;
  }
    

I have already tried this, but it doesn't work for me!

md-menu override default max-width in Angular 2

like image 444
Siju Samson Avatar asked Jul 13 '18 13:07

Siju Samson


People also ask

How do I make a mat-menu wider?

Just wrap the content of the mat-menu and apply the width to the wrapper itself, like in the following example:

How do I change the width of my menu?

To change the width of your menu you can add the following CSS to your menu theme by going to Mega Menu > Menu Themes > Custom CSS.

How do I change the size of a mat icon?

The default size of a mat icon is 24px. Which basically means that the properties are set to 24px. So, if you want to change the size of a mat-icon, you should always change the value of the font-size, width and height and keep all three values the same to avoid any problem. .

How to change the menu position using mat-menu selector?

To change the menu position we can use xPosition and yPosition properties of mat-menu selector. If you want display menu before and after the menu trigger element we can pass xPosition value as “before” or “after”.


2 Answers

i had the same issue and solved it by overriding the mat-menu-panel max width property:

::ng-deep.mat-menu-panel {
  max-width: none !important;
}

hope it helps

like image 179
gil Avatar answered Sep 18 '22 08:09

gil


https://material.angular.io/components/menu/api

@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.

<mat-menu class="my-class" ... >

component css (needs ng-deep due to cdk-overlay):

::ng-deep {.mat-menu-panel.my-class { width: 400px; } }
like image 28
Stefan Norberg Avatar answered Sep 19 '22 08:09

Stefan Norberg