Skip to content

bug(mat-menu): Attempting to attach an unknown Portal type #30686

Closed
@JuNe98

Description

@JuNe98

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

19.2.3

Description

Since @angular/material version 19.2.4 I am getting the following error when I try to open a mat-menu:

Image

It works smoothly with any Angular Material version before 19.2.4.

Reproduction

I was not able to reproduce this bug in stackblitz. I am not sure if it makes any differences but I am using NX in my repo.

EDIT: Successfully reproduced in a public repo: https://github.com/JuNe98/nx-menu-bug

My HTML template:

<button mat-button [matMenuTriggerFor]="menu" dmThemeAccent>
  <div class="language-selector-button-content">
    <img [src]="currentLanguageImage()" alt="Language" class="language-image" />
    <mat-icon>keyboard_arrow_down</mat-icon>
  </div>
</button>
<mat-menu #menu="matMenu" class="language-select-panel">
  <div class="language-menu-header">
    <span class="language-menu-label">{{ 'language' | t | cap }}</span>
  </div>
  @for (item of allLanguages(); track item.key) {
  <button
    mat-menu-item
    [class]="{ 'selected-language': item.key === currentLanguage(), 'language-slector-menu-item': true }"
    (click)="changeLanguage(item.key)"
  >
    <div class="language-selector-item-button-content">
      <div class="language-selector-item-button-content-main">
        <img [src]="item.iconFile" alt="Language" class="language-image" />
        <span>{{ item.language }}</span>
      </div>
      @if(item.key === currentLanguage()) {
      <mat-icon>check</mat-icon>
      }
    </div>
  </button>
  }
</mat-menu>

My component:

import { Component, inject, signal, computed } from '@angular/core';
import { CommonModule } from '@angular/common';
import { REGISTERED_LANGUAGES, ThemeAccentDirective, TranslatePipe, TranslationService } from '@my-lib';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { MatMenuModule } from '@angular/material/menu';
import { CapitalizePipe } from '../../../pipes';

@Component({
  selector: 'idp-language-selector',
  imports: [CommonModule, MatIconModule, MatButtonModule, MatMenuModule, TranslatePipe, CapitalizePipe, ThemeAccentDirective],
  templateUrl: './language-selector.component.html',
  styleUrl: './language-selector.component.scss',
})
export class LanguageSelectorComponent {
  private readonly translationService = inject(TranslationService);
  readonly allLanguages = signal(inject(REGISTERED_LANGUAGES));
  currentLanguage = signal<string | undefined>(undefined);

  currentLanguageImage = computed(() => {
    return this.allLanguages().find((lang) => lang.key === this.currentLanguage())?.iconFile;
  });

  constructor() {
    this.currentLanguage.set(this.translationService.getCurrentLocale());
  }

  changeLanguage(language: string) {
    this.currentLanguage.set(language);
    this.translationService.changeLocale(language);
  }
}

This are my dependencies:

"dependencies": {
    "@angular/animations": "^19.2.3",
    "@angular/cdk": "19.2.6",
    "@angular/common": "^19.2.3",
    "@angular/compiler": "^19.2.3",
    "@angular/core": "^19.2.3",
    "@angular/forms": "^19.2.3",
    "@angular/material": "19.2.6",
    "@angular/material-luxon-adapter": "19.2.6",
    "@angular/platform-browser": "^19.2.3",
    "@angular/platform-browser-dynamic": "^19.2.3",
    "@angular/router": "^19.2.3",
    "@fontsource/inter": "^5.2.5",
    "@softarc/native-federation-node": "^2.0.10",
    "ag-grid-angular": "^33.1.1",
    "ag-grid-community": "^33.1.1",
    "ajv": "^8.17.1",
    "ajv-formats": "^3.0.1",
    "angular-gridster2": "^19.0.0",
    "echarts": "^5.6.0",
    "es-module-shims": "^2.0.9",
    "keycloak-angular": "^19.0.2",
    "keycloak-js": "^26.1.4",
    "luxon": "^3.5.0",
    "material-symbols": "^0.29.2",
    "monaco-editor": "^0.52.2",
    "ngx-echarts": "^19.0.0",
    "ngx-markdown": "^19.1.1",
    "ngx-monaco-editor-v2": "^19.0.2",
    "rxjs": "~7.8.0",
    "zone.js": "~0.15.0"
  },
  "devDependencies": {
    "@analogjs/platform": "^1.14.1",
    "@analogjs/vite-plugin-angular": "^1.14.1",
    "@analogjs/vitest-angular": "^1.14.1",
    "@angular-architects/native-federation": "^19.0.16",
    "@angular-devkit/build-angular": "^19.2.4",
    "@angular-devkit/core": "^19.2.4",
    "@angular-devkit/schematics": "^19.2.4",
    "@angular/cli": "^19.2.4",
    "@angular/compiler-cli": "^19.2.3",
    "@angular/language-service": "^19.2.3",
    "@eslint/js": "^9.8.0",
    "@module-federation/enhanced": "0.8.8",
    "@nx/angular": "20.6.2",
    "@nx/devkit": "20.6.2",
    "@nx/esbuild": "20.6.2",
    "@nx/eslint": "20.6.2",
    "@nx/eslint-plugin": "20.6.2",
    "@nx/jest": "20.6.2",
    "@nx/js": "20.6.2",
    "@nx/module-federation": "20.6.2",
    "@nx/playwright": "20.6.2",
    "@nx/vite": "20.6.2",
    "@nx/web": "20.6.2",
    "@nx/webpack": "20.6.2",
    "@nx/workspace": "20.6.2",
    "@openapitools/openapi-generator-cli": "^2.16.3",
    "@playwright/test": "^1.36.0",
    "@schematics/angular": "19.2.3",
    "@swc-node/register": "~1.9.1",
    "@swc/core": "~1.5.7",
    "@swc/helpers": "~0.5.11",
    "@types/jest": "^29.5.12",
    "@types/luxon": "^3.4.2",
    "@types/node": "18.16.9",
    "@typescript-eslint/utils": "^8.13.0",
    "@vitest/coverage-v8": "^3.0.9",
    "@vitest/ui": "^3.0.9",
    "angular-eslint": "^19.2.1",
    "autoprefixer": "^10.4.0",
    "esbuild": "^0.19.2",
    "eslint": "^9.8.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-playwright": "^1.6.2",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-preset-angular": "~14.5.3",
    "jsdom": "~22.1.0",
    "jsonc-eslint-parser": "^2.1.0",
    "marked": "^15.0.6",
    "ng-packagr": "19.2.0",
    "nx": "20.6.2",
    "nx-stylelint": "^18.0.0",
    "patch-package": "^8.0.0",
    "postcss": "^8.4.5",
    "postcss-url": "~10.1.3",
    "prettier": "^2.6.2",
    "stylelint": "^16.10.0",
    "stylelint-config-standard": "^36.0.1",
    "stylelint-config-standard-scss": "^14.0.0",
    "tailwindcss": "^3.0.2",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "tslib": "^2.3.0",
    "typescript": "5.7.3",
    "typescript-eslint": "^8.26.1",
    "vite": "^6.2.2",
    "vite-tsconfig-paths": "^5.1.4",
    "vitest": "^3.0.9"
  }

Expected Behavior

Should open the MatMenu without any erros.

Actual Behavior

Nothing, only error in the console shows up.

Environment

  • Angular: 19.2.3
  • CDK/Material: =<19.2.4
  • Browser(s): Google Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue needs to be triaged by the teamneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions