Skip to content

Commit 98cccb0

Browse files
committed
docs(material/dialog): clarify that default options replace rather than merge
Add a note to the dialog documentation explaining that providing MAT_DIALOG_DEFAULT_OPTIONS (or DEFAULT_DIALOG_CONFIG for CDK) replaces the entire built-in config rather than merging with it. Include the workaround of spreading the defaults for partial overrides. Also update the code examples to use bootstrapApplication and "app config" prose for consistency. Closes #20631
1 parent b095048 commit 98cccb0

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/cdk/dialog/dialog.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,28 @@ class MyDialogContainer extends CdkDialogContainer {}
117117

118118
### Specifying global configuration defaults
119119
Default dialog options can be specified by providing an instance of `DialogConfig` for
120-
`DEFAULT_DIALOG_CONFIG` in your application's root module.
120+
`DEFAULT_DIALOG_CONFIG` in your app config.
121121

122122
```ts
123-
@NgModule({
123+
bootstrapApplication(MyApp, {
124124
providers: [
125125
{provide: DEFAULT_DIALOG_CONFIG, useValue: {hasBackdrop: false}}
126126
]
127-
})
127+
});
128128
```
129129

130+
> **Note:** The value provided for `DEFAULT_DIALOG_CONFIG` **replaces** the built-in defaults
131+
> entirely rather than merging with them. For example, providing `{disableClose: true}` means that
132+
> all other defaults (such as `hasBackdrop`) will be `undefined`. If you only want to override
133+
> specific properties, spread the defaults first:
134+
>
135+
> ```ts
136+
> {provide: DEFAULT_DIALOG_CONFIG, useValue: {...new DialogConfig(), disableClose: true}}
137+
> ```
138+
>
139+
> When you call `dialog.open()` with a config, that config is merged on top of these defaults, so
140+
> per-dialog options always take precedence.
141+
130142
### Sharing data with the Dialog component.
131143
You can use the `data` option to pass information to the dialog component.
132144

src/material/dialog/dialog.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,28 @@ export class YourDialog {
4141

4242
### Specifying global configuration defaults
4343
Default dialog options can be specified by providing an instance of `MatDialogConfig` for
44-
MAT_DIALOG_DEFAULT_OPTIONS in your application's root module.
44+
MAT_DIALOG_DEFAULT_OPTIONS in your app config.
4545

4646
```ts
47-
@NgModule({
47+
bootstrapApplication(MyApp, {
4848
providers: [
4949
{provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
5050
]
51-
})
51+
});
5252
```
5353

54+
> **Note:** The value provided for `MAT_DIALOG_DEFAULT_OPTIONS` **replaces** the built-in defaults
55+
> entirely rather than merging with them. For example, providing `{disableClose: true}` means that
56+
> all other defaults (such as `hasBackdrop`) will be `undefined`. If you only want to override
57+
> specific properties, spread the defaults first:
58+
>
59+
> ```ts
60+
> {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {...new MatDialogConfig(), disableClose: true}}
61+
> ```
62+
>
63+
> When you call `dialog.open()` with a config, that config is merged on top of these defaults, so
64+
> per-dialog options always take precedence.
65+
5466
### Sharing data with the Dialog component.
5567
If you want to share data with your dialog, you can use the `data`
5668
option to pass information to the dialog component.

0 commit comments

Comments
 (0)