Skip to content

Commit e433a66

Browse files
yogeshwaran-cadolgachev
authored andcommitted
docs(material/dialog): clarify that default options replace rather than merge (#32819)
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 (cherry picked from commit 1dc6b44)
1 parent c9d40aa commit e433a66

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/cdk/dialog/dialog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ bootstrapApplication(MyApp, {
129129
});
130130
```
131131

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

src/material/dialog/dialog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ bootstrapApplication(MyApp, {
5353
});
5454
```
5555

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

0 commit comments

Comments
 (0)