MudDialog.Options are not used when dialog is open by MudDialog.ShowAsync()
Before reporting
- I searched existing issues
- I tried in private/incognito browser
What went wrong?
MudDialog component contains the property MudDialog.Options that according to the docs:
"The default options for this dialog. These options are used if none are provided during the MudBlazor.MudDialog.ShowAsync(System.String,MudBlazor.DialogOptions) method. This is typically used for inline dialogs."
The real behavior is that MudDialog.Options are only used in inline dialogs (when the dialog is not open by MudDialog.ShowAsync()).
Seems like all overloads of MudDialog.ShowAsync() provide some DialogOptions; from the method param o using DialogOptions.Default.
The only way I found to add default DialogOptions to a dialog is by setting them on initialization (inside my "TestDialog.razor" component):
protected override async Task OnInitializedAsync()
{
await MudDialog.SetOptionsAsync(MyDefaultOptions);
}But this always override DialogOptions provided by the page when opening the dialog using MudDialog.ShowAsync().
In conclusion, there is no way to achieve the behavior described in the docs: set default options for your dialog component when no options are provided by MudDialog.ShowAsync.
Proposed fixes
I have some proposals:
- Keep current behavior and update the docs so they clarify the current behavior: Property "MudDialog.Options" only apply for inline dialogs.
- Change the behavior.
Some ideas to change the behavior:
DialogOptions.Defaultis only used when no options are already provided (by the MudDialog.Options property or by theMudDialog.ShowAsync()method. (No changes required to the docs?)- Add some method to check if the DialogOptions (
MudDialog.Options) where added by the user or by default (right now,DialogOptions.Defaultis internal, so it's not possible to check if the currentMudDialog.Optionsare the default and apply your own defaults. Required changes to the docs, but the user can do this to achieve the expected behavior:
protected override async Task OnInitializedAsync()
{
if (MudDialog.Options == DialogOptions.Default)
{
await MudDialog.SetOptionsAsync(DefaultOptions);
}
}Reproduction link
https://try.mudblazor.com/snippet/mEcAEsFEyqBEnwqq
Reproduction steps
- Try button "Open with options" -> Dialog with
MaxWidth.ExtraLargeshould open as the DialogOptions from the page are used. - Try button "Open without options" -> No options are provided by the page when opening the dialog component. A FullScreen dialog is expected as TestDialog component default
DialogOptions.
Version (bug)
v9.8.0
Version (working)
Not tested
Environment
Chrome, Firefox
Blazor rendering mode
Server
Source: MudBlazor/MudBlazor