Skip to content

Commit ec927bd

Browse files
Merge pull request #23 from stavroskasidis/release/3.1.0
Added `ForceAllowNavigation` and `ForcePreventNavigation` methods to …
2 parents 0f07475 + 4876eb4 commit ec927bd

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

BlazorDialog/BlazorDialog.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Copyright />
1313
<PackageTags>blazor blazor-component blazor-dialog dialog modal blazor-modal blazordialog blazormodaldialog blazormodal razor razor-components razorcomponents</PackageTags>
1414
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
15-
<Version>3.0.0</Version>
15+
<Version>3.1.0</Version>
1616
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
1717
<Product>BlazorDialog</Product>
1818
</PropertyGroup>

BlazorDialog/Components/Dialog.razor

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
/// </summary>
106106
[Parameter] public bool PreventNavigation { get; set; } = true;
107107

108+
private bool? _forcedPreventNavigation;
108109
protected TaskCompletionSource<object> taskCompletionSource;
109110
internal Action<object> OnDialogHide;
110111
protected void NotifyDialogHidden(object result) => OnDialogHide?.Invoke(result);
@@ -305,6 +306,27 @@
305306
return this.isShowing;
306307
}
307308

309+
internal bool GetPreventNavigation()
310+
{
311+
if (_forcedPreventNavigation.HasValue) return _forcedPreventNavigation.Value;
312+
return this.PreventNavigation;
313+
}
314+
315+
/// <summary>
316+
/// Forces the dialog to allow navigation when shown, regardless of the <see cref="PreventNavigation" /> property.
317+
/// </summary>
318+
public void ForceAllowNavigation()
319+
{
320+
_forcedPreventNavigation = false;
321+
}
322+
323+
/// <summary>
324+
/// Forces the dialog to prevent navigation when shown, regardless of the <see cref="PreventNavigation" /> property.
325+
/// </summary>
326+
public void ForcePreventNavigation()
327+
{
328+
_forcedPreventNavigation = true;
329+
}
308330

309331
protected override Task OnAfterRenderAsync(bool firstRender)
310332
{

BlazorDialog/LocationChangingHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void RegisterLocationChangingHandler(Dialog dialog)
3434

3535
private ValueTask OnLocationChanging(LocationChangingContext context)
3636
{
37-
if (!context.IsNavigationIntercepted && _dialogsStack.Any(x => x.PreventNavigation))
37+
if (!context.IsNavigationIntercepted && _dialogsStack.Any(x => x.GetPreventNavigation()))
3838
{
3939
context.PreventNavigation();
4040
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ Make sure that there is a call to `app.UseStaticFiles();` in your server project
8181
</details>
8282
8383
## Release Notes
84-
<details open="open"><summary>3.0</summary>
84+
85+
<details open="open"><summary>3.1</summary>
86+
87+
>- Added `ForceAllowNavigation` and `ForcePreventNavigation` methods to the `Dialog` component to allow/prevent navigation regardless of the `PreventNavigation` parameter.
88+
</details>
89+
90+
91+
<details><summary>3.0</summary>
8592

8693
>- Migrate to .NET 8.0
8794
>- Add PreventNavigation option to prevent navigation when dialog is open.

TestApps/BlazorDialog.TestAppsCommon/IndexCommon.razor

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<option value="@DialogAnimation.Zoom">@DialogAnimation.Zoom</option>
2424
<option value="@DialogAnimation.FadeIn">@DialogAnimation.FadeIn</option>
2525
</select>
26-
<Dialog Id="simple-large-dialog" Size="size" Centered="isCentered" Animation="animation" CssClass="custom-class">
26+
<Dialog Id="simple-large-dialog" Size="size" Centered="isCentered" Animation="animation" CssClass="custom-class" @ref="simpleLargeDialog">
2727
<DialogInputProvider TInput="string">
2828
<DialogHeader ShowClose="true">
2929
<h4>@context.Input</h4>
@@ -128,6 +128,7 @@
128128

129129
<button @onclick="SimpleDialogOnClick">Simple Dialog</button>
130130
<button @onclick="SimpleDialogBigOnClick">Simple Dialog Big</button>
131+
<button @onclick="SimpleLargeDialogDisablePreventNavigation">Simple Dialog Big allow navigation</button>
131132

132133
@if (dialogResult != null)
133134
{
@@ -139,6 +140,7 @@
139140
bool isCentered;
140141
DialogSize size;
141142
DialogAnimation animation;
143+
Dialog simpleLargeDialog;
142144

143145
async Task SimpleDialogOnClick()
144146
{
@@ -149,4 +151,9 @@
149151
{
150152
dialogResult = await dialogService.ShowDialog<string>("simple-large-dialog", "(Simple Dialog Large) Are you sure?");
151153
}
154+
155+
void SimpleLargeDialogDisablePreventNavigation()
156+
{
157+
simpleLargeDialog.ForceAllowNavigation();
158+
}
152159
}

0 commit comments

Comments
 (0)