-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
MudDialogProvider: Add CloseOnNavigation to DialogOptions to optionally close dialogs on navigation #12437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MudDialogProvider: Add CloseOnNavigation to DialogOptions to optionally close dialogs on navigation #12437
Changes from all commits
482feb8
174f38b
c579082
77cf33a
b63a2c2
3b9d5b3
89d6df5
e8262e7
5116f05
919ba1c
094b100
eff238d
0ecf569
01cf77d
64ea638
033f9ce
668eb68
88abb94
4f52097
721c1a0
fa6fea7
c916666
481e6c3
df6e6df
b601329
e52e787
5feaf46
3695a5a
4883b85
a547685
92350c5
867f685
5abe682
915d2b9
aa7d8a4
166c04d
79ae8af
a008355
df687e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||
| using AwesomeAssertions; | ||||||||||||||||||||||||||||||||||
| using System.Web; | ||||||||||||||||||||||||||||||||||
| using AwesomeAssertions; | ||||||||||||||||||||||||||||||||||
| using Bunit; | ||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Components; | ||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Components.Web; | ||||||||||||||||||||||||||||||||||
|
|
@@ -91,6 +92,39 @@ public async Task Simple() | |||||||||||||||||||||||||||||||||
| result.Canceled.Should().BeFalse(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||
| /// Opening and closing dialogs via navigation. | ||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||
| [Test] | ||||||||||||||||||||||||||||||||||
| public async Task CloseOnNavigationTest() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| var comp = Context.Render<MudDialogProvider>(); | ||||||||||||||||||||||||||||||||||
| comp.Markup.Trim().Should().BeEmpty(); | ||||||||||||||||||||||||||||||||||
| var dialogService = Context.Services.GetRequiredService<IDialogService>(); | ||||||||||||||||||||||||||||||||||
| dialogService.Should().NotBe(null); | ||||||||||||||||||||||||||||||||||
| var navigationManager = Context.Services.GetRequiredService<NavigationManager>(); | ||||||||||||||||||||||||||||||||||
| navigationManager.Should().NotBe(null); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| //create 2 instances and dismiss all except for one with CloseOnNavigation = false | ||||||||||||||||||||||||||||||||||
| var closeOnNavigationOptions = new DialogOptions | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| CloseOnNavigation = false | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| await comp.InvokeAsync(async () => _ = await dialogService.ShowAsync<DialogOkCancel>("test", options: closeOnNavigationOptions)); | ||||||||||||||||||||||||||||||||||
| await comp.InvokeAsync(async () => _ = await dialogService.ShowAsync<DialogOkCancel>()); | ||||||||||||||||||||||||||||||||||
| var cont = comp.FindAll("div.mud-dialog-container"); | ||||||||||||||||||||||||||||||||||
| cont.Count.Should().Be(2); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| var uri = new Uri(navigationManager.Uri); | ||||||||||||||||||||||||||||||||||
| var query = HttpUtility.ParseQueryString(uri.Query); | ||||||||||||||||||||||||||||||||||
| query["query"] = Guid.NewGuid().ToString(); | ||||||||||||||||||||||||||||||||||
| var newUri = $"{uri.GetLeftPart(UriPartial.Path)}?{query}"; | ||||||||||||||||||||||||||||||||||
| await comp.InvokeAsync(() => navigationManager.NavigateTo(newUri)); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
1
to
122
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| cont = comp.FindAll("div.mud-dialog-container"); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+121
to
+124
|
||||||||||||||||||||||||||||||||||
| var newUri = $"{uri.GetLeftPart(UriPartial.Path)}?{query}"; | |
| await comp.InvokeAsync(() => navigationManager.NavigateTo(newUri)); | |
| cont = comp.FindAll("div.mud-dialog-container"); | |
| var newUriWithQueryChange = $"{uri.GetLeftPart(UriPartial.Path)}?{query}"; | |
| await comp.InvokeAsync(() => navigationManager.NavigateTo(newUriWithQueryChange)); | |
| // Changing only the query string should not close dialogs when CloseOnNavigation is null (default) | |
| cont = comp.FindAll("div.mud-dialog-container"); | |
| cont.Count.Should().Be(2); | |
| // Changing the path should close dialogs with default CloseOnNavigation, but keep those with CloseOnNavigation = false | |
| var newUriWithPathChange = $"{uri.GetLeftPart(UriPartial.Path)}-other"; | |
| await comp.InvokeAsync(() => navigationManager.NavigateTo(newUriWithPathChange)); | |
| cont = comp.FindAll("div.mud-dialog-container"); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InjectOptions(null) does not compile with the current IDialogReference.InjectOptions(DialogOptions options) signature. Either make InjectOptions accept nullable options, or update these tests to avoid passing null (e.g., verify behavior with CloseOnNavigation = null on a real DialogOptions instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test, options are not required on construction of a reference, neither is the RenderFragment or the Dialog instance itself. This is edge case test for a poorly configured IDialogReference.
It will compile it just has a warning on the test case.
(e.g., verify behavior with CloseOnNavigation = null on a real DialogOptions instance). This is verified in other tests in the same file.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InjectOptions(null) does not compile with the current IDialogReference.InjectOptions(DialogOptions options) signature. Either make InjectOptions accept nullable options, or update these tests to avoid passing null (e.g., verify behavior with CloseOnNavigation = null on a real DialogOptions instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a test, options are not required on construction of a reference, neither is the RenderFragment or the Dialog instance itself. This is edge case test for a poorly configured IDialogReference.
It will compile it just has a warning on the test case.
(e.g., verify behavior with CloseOnNavigation = null on a real DialogOptions instance). This is verified in other tests in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@using System.Web/HttpUtility.ParseQueryStringintroduces a dependency that isn't referenced in the docs project (and is generally avoided in Blazor). SinceMudBlazor.Docsalready referencesMicrosoft.AspNetCore.WebUtilities, consider usingQueryHelpers.AddQueryString(orUriBuilder) to update the query string without relying onSystem.WebAPIs.