Skip to content

bug(dialog): Throw an error if MatDialog with CDK DialogRef are mixed by mistake #33601

Description

@robmv

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

No response

Description

I lost hours trying to make DialogRef's disableClose to work, even when I have dozens of dialogs doing the same thing, disabling the easy close of the dialog when a form is dirty.

The simple fix was to not use DialogRef, because the dialog was open with MatDialog, not with CDK's Dialog.

Reproduction

StackBlitz link: https://stackblitz.com/edit/ahexqiuq?file=src%2Fexample%2Fdialog-content-example.ts

Steps to reproduce:

  1. Open the dialog on the test.
  2. The dialog can be closed with the Esc key.
  3. Edit the source code and enable the line private readonly dialogRef = inject(MatDialogRef); instead of private readonly dialogRef = inject(DialogRef);
  4. The dialog can not be closed with the Esc key.

Expected Behavior

In an ideal world injecting a more generic version of DialogRef should not be a problem, it is what someone expect from inheritance, for example using a more generic type for a variable, but as injection is not a simple type declaration, maybe it is not possible. In this case I expect an error injecting a plain CDK DialogRef in a component that was open by MatDialog. not getting a DialogRef that is not functional.

Actual Behavior

A DialogRef instance is injected without errors but that is non functional, at least the disableClose property.

Environment

  • Angular: 22.1.0
  • CDK/Material: 22.1.0
  • Browser(s): Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Fedora Linux

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/dialoggemini-triagedLabel noting that an issue has been triaged by gemini

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions