Skip to content

bug(mat-menu): ng-container inside the mat-menu-item causes bug with vertical alignment with icon #26638

@Londeren

Description

@Londeren

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

Angular / Material 14

Description

If wrap a content of mat-menu-item in ng-container it breaks vertical alignment for mat-icon and corresponding item text.

<button
  mat-icon-button
  [matMenuTriggerFor]="menu"
  aria-label="Example icon-button with a menu"
>
  <mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
  <button mat-menu-item> ← works fine without wrapper
    <mat-icon>dialpad</mat-icon>
    <span>Redial</span>
  </button>
  <button mat-menu-item>
    <ng-container> ← breaks the alignment
      <mat-icon>voicemail</mat-icon>
      <span>Check voice mail</span>
    </ng-container>
  </button>
</mat-menu>

Reproduction

Steps to reproduce:
Please, see the example on stackblitz

  1. Wrap mat-menu-item in ng-container like this:
<button mat-menu-item>
    <ng-container>
      <mat-icon>voicemail</mat-icon>
      <span>Check voice mail</span>
    </ng-container>
  </button>

Expected Behavior

screenshot 1

Actual Behavior

Broken vertical alignment:

screenshot

Environment

  • Angular: 15.0.0 / 15.1.4
  • CDK/Material: 15.1.4
  • Browser(s): Any
  • Operating System (e.g. Windows, macOS, Ubuntu): Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions