Skip to content

bug(dialog): usage of MAT_DIALOG_DEFAULT_OPTIONS resets default options #28096

Open
@DanielHabenicht

Description

@DanielHabenicht

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

This is either a documentation issue or an issue with the behaviour of MAT_DIALOG_DEFAULT_OPTIONS.

When specifying

{
    provide: MAT_DIALOG_DEFAULT_OPTIONS,
    useValue: {
        panelClass: 'mat-field-inside-dialog-workaround',
    } as MatDialogConfig
}

The autoFocus of dialogs gets disabled, this is unexpected as the developer never stated it to be disabled and the documentation states:

When opened, MatDialog traps browser focus such that it cannot escape the root role="dialog" element. By default, the first tabbable element in the dialog receives focus. You can customize which element receives focus with the autoFocus property of MatDialogConfig, which supports the following values.

Reproduction

StackBlitz link: https://stackblitz.com/edit/kxsrvy?file=src%2Fexample%2Fdialog-overview-example.ts
Steps to reproduce:

  1. Open Dialog
  2. There is no focus set on the input
  3. Comment out the MAT_DIALOG_DEFAULT_OPTIONS in main.ts.
  4. Open Dialog
  5. There is focus set on the input

Expected Behavior

The default should be kept,

Otherwise the documentation should be revised that overwriting another property can change others.

Actual Behavior

Overwriting one property of MatDialogConfig in MAT_DIALOG_DEFAULT_OPTIONS changes the default behaviour of unrelated (not overwritten properties).

Environment

  • Angular: 16.2.5
  • CDK/Material: 16.2.12
  • Browser(s): Edge
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11

Activity

changed the title [-]bug(dialog): MAT_DIALOG_DEFAULT_OPTIONS resets default options[/-] [+]bug(dialog): usage of MAT_DIALOG_DEFAULT_OPTIONS resets default options[/+] on Nov 9, 2023
added
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
and removed
needs triageThis issue needs to be triaged by the team
on Nov 10, 2023
MFredX

MFredX commented on Mar 11, 2025

@MFredX

This bug is observed in v19 as well.

If anyone is wanting a workaround for this, initialise the base config and overwrite the fields important to you

const myOptions = {
...new MatDialogConfig(),
 panelClass: 'mat-field-inside-dialog-workaround'
}

/* In your provider definitions */
providers : [
 {
    provide: MAT_DIALOG_DEFAULT_OPTIONS,
    useValue: myOptions
 }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/dialog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DanielHabenicht@wagnermaciel@MFredX

        Issue actions

          bug(dialog): usage of MAT_DIALOG_DEFAULT_OPTIONS resets default options · Issue #28096 · angular/components