Repository: MudBlazor/MudBlazor (2026-04-15T18:45:09Z)

Issue:
BackgroundClass from MudDialogProvider is not applied to ShowMessageBoxAsync
### Before reporting

- [x] I searched existing issues
- [x] I tried in private/incognito browser

### What went wrong?

I've been trying to set a global backgroundclass for MudDialog instances. However it doesn't seem to be working.

Is there an issue on my side, or does this just not work that way? In my understanding, both results should be the same because I've setup MudBlazor like this:
`<MudDialogProvider BackgroundClass="blurry-dialog-background"/>`

But ` await Dialog.ShowMessageBoxAsync("Title", "Message");` results in not blurred.
<img width="667" height="347" alt="Image" src="https://github.com/user-attachments/assets/020d0aec-a315-4fee-8f75-27e7726cfb1c" />

Whereas this shows the blurred background. `await Dialog.ShowMessageBoxAsync("Title", "Message", options: new DialogOptions{ BackgroundClass = "blurry-dialog-background"});`
<img width="571" height="347" alt="Image" src="https://github.com/user-attachments/assets/3c35bca4-3205-417e-b2dd-1b881af4c804" />


### Reproduction link

https://github.com/phamilton4321/MudBlazerIssueBackgroundClass.git

### Reproduction steps

1. Use my sample repo to setup a sample page.
2. Open Dialog without inline options set and the ones with inline options.
3. The dialogs without inline options do not show the drop shadow.



### Version (bug)

9.3.0

### Version (working)

_No response_

### Environment

Edge

### Blazor rendering mode

Server


Discussion:

Patch:
diff --git a/src/MudBlazor/Components/Dialog/MudDialogContainer.razor.cs b/src/MudBlazor/Components/Dialog/MudDialogContainer.razor.cs
index 01ccad698da9..5c77d6d14d10 100644
--- a/src/MudBlazor/Components/Dialog/MudDialogContainer.razor.cs
+++ b/src/MudBlazor/Components/Dialog/MudDialogContainer.razor.cs
@@ -125,7 +125,7 @@ public MudDialogContainer()
             new CssBuilder("mud-overlay-dialog")
                 .AddClass($"mud-skip-overlay-section") // dialog overlay remains outside of Section
                 .AddClass("mud-skip-overlay-positioning") // popovers try to position the overlay by zindex, this skips that behavior if a user puts the dialog provider above the popover provider
-                .AddClass(GetDialogOptionsOrDefault.BackgroundClass)
+                .AddClass(GetBackgroundClass())
                 .Build();
 
         protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -300,6 +300,8 @@ private string GetMaxWidth()
 
         private bool GetFullScreen() => GetDialogOptionsOrDefault.FullScreen ?? GlobalDialogOptions.FullScreen ?? false;
 
+        private string? GetBackgroundClass() => GetDialogOptionsOrDefault.BackgroundClass ?? GlobalDialogOptions.BackgroundClass;
+
         private DialogOptions GetDialogOptionsOrDefault => _dialogOptionsState.Value ?? DialogOptions.Default;
 
         protected virtual async ValueTask DisposeAsyncCore()


Test patch:
diff --git a/src/MudBlazor.UnitTests/Components/MessageBoxTests.cs b/src/MudBlazor.UnitTests/Components/MessageBoxTests.cs
index 6761212adbdb..aa6f6d13e2f3 100644
--- a/src/MudBlazor.UnitTests/Components/MessageBoxTests.cs
+++ b/src/MudBlazor.UnitTests/Components/MessageBoxTests.cs
@@ -318,5 +318,44 @@ await comp.InvokeAsync(async () =>
 
             dialogResult?.Result.Data?.Should().BeNull();
         }
+
+        [Test]
+        public async Task MessageBox_Should_UseGlobalBackgroundClass_WhenOptionsAreNotProvided()
+        {
+            var provider = Context.Render<MudDialogProvider>(builder => builder.Add(x => x.BackgroundClass, "global-background"));
+            var service = Context.Services.GetService<IDialogService>() as DialogService;
+            service.Should().NotBeNull();
+            Task<bool?> messageBoxTask = null!;
+
+            await provider.InvokeAsync(() =>
+            {
+                messageBoxTask = service!.ShowMessageBoxAsync("Boom!", "I'm a pickle. What do you make of that?");
+            });
+
+            provider.Find("div.mud-overlay-dialog").ClassList.Should().Contain("global-background");
+            await provider.Find(".mud-message-box__yes-button").ClickAsync();
+            (await messageBoxTask).Should().BeTrue();
+        }
+
+        [Test]
+        public async Task MessageBox_Should_PreferExplicitBackgroundClass_OverGlobalBackgroundClass()
+        {
+            var provider = Context.Render<MudDialogProvider>(builder => builder.Add(x => x.BackgroundClass, "global-background"));
+            var service = Context.Services.GetService<IDialogService>() as DialogService;
+            service.Should().NotBeNull();
+            var dialogOptions = new DialogOptions { BackgroundClass = "explicit-background" };
+            Task<bool?> messageBoxTask = null!;
+
+            await provider.InvokeAsync(() =>
+            {
+                messageBoxTask = service!.ShowMessageBoxAsync("Boom!", "I'm a pickle. What do you make of that?", options: dialogOptions);
+            });
+
+            var overlayClasses = provider.Find("div.mud-overlay-dialog").ClassList;
+            overlayClasses.Should().Contain("explicit-background");
+            overlayClasses.Should().NotContain("global-background");
+            await provider.Find(".mud-message-box__yes-button").ClickAsync();
+            (await messageBoxTask).Should().BeTrue();
+        }
     }
 }