Skip to content

Commit 5a6f98b

Browse files
Merge pull request #29 from stavroskasidis/release/4.1.0
Release 4.1.0
2 parents afada78 + 288337e commit 5a6f98b

32 files changed

Lines changed: 331 additions & 177 deletions

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>4.0.1</Version>
15+
<Version>4.1.0</Version>
1616
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
1717
<Product>BlazorDialog</Product>
1818
</PropertyGroup>

BlazorDialog/BlazorDialogService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Task ShowComponentAsDialog(ComponentAsDialogOptions options)
3030
return ShowComponentAsDialog<object>(options);
3131
}
3232

33-
public async Task<TResult> ShowComponentAsDialog<TResult>(ComponentAsDialogOptions options)
33+
public async Task<TResult?> ShowComponentAsDialog<TResult>(ComponentAsDialogOptions options)
3434
{
3535
var id = Guid.NewGuid().ToString();
3636
var tcs = new TaskCompletionSource();
@@ -49,17 +49,17 @@ public async Task ShowDialog(string dialogId)
4949
await ShowDialog<object>(dialogId, null);
5050
}
5151

52-
public async Task<TResult> ShowDialog<TResult>(string dialogId)
52+
public async Task<TResult?> ShowDialog<TResult>(string dialogId)
5353
{
5454
return await ShowDialog<TResult>(dialogId, null);
5555
}
5656

57-
public async Task ShowDialog(string dialogId, object input)
57+
public async Task ShowDialog(string dialogId, object? input)
5858
{
5959
await ShowDialog<object>(dialogId, input);
6060
}
6161

62-
public async Task<TResult> ShowDialog<TResult>(string dialogId, object input)
62+
public async Task<TResult?> ShowDialog<TResult>(string dialogId, object? input)
6363
{
6464
return await _blazorDialogStore.GetById(dialogId).Show<TResult>(input);
6565
}

BlazorDialog/BlazorDialogStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class BlazorDialogStore : IBlazorDialogStore
1212
private Dictionary<string, Dialog> registeredDialogs = new Dictionary<string, Dialog>();
1313
private Dictionary<string, ComponentDialog> registeredComponentDialogs = new Dictionary<string, ComponentDialog>();
1414

15-
public event Func<Task> OnComponentAsDialogsChanged;
15+
public event Func<Task>? OnComponentAsDialogsChanged;
1616

1717
public Dialog GetById(string id)
1818
{

BlazorDialog/Components/ComponentAsDialogContainer.razor

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Dialog Id="@Key" Animation="ComponentDialog.Options.Animation" BaseZIndex="ComponentDialog.Options.BaseZIndex"
77
Centered="ComponentDialog.Options.Centered" CssClass="@ComponentDialog.Options.CssClass" Size="ComponentDialog.Options.Size"
88
OnAfterRender="EventUtil.AsNonRenderingEventCallback((bool firstLoad) => OnAfterDialogRender(firstLoad))"
9-
OnAfterHide="ComponentDialog.Options.OnAfterHide" OnAfterShow="ComponentDialog.Options.OnAfterShow"
10-
OnBeforeHide="ComponentDialog.Options.OnBeforeHide" OnBeforeShow="ComponentDialog.Options.OnBeforeShow"
9+
OnAfterHide="ComponentDialog.Options.OnAfterHide!" OnAfterShow="ComponentDialog.Options.OnAfterShow!"
10+
OnBeforeHide="ComponentDialog.Options.OnBeforeHide!" OnBeforeShow="ComponentDialog.Options.OnBeforeShow!"
1111
PreventNavigation="ComponentDialog.Options.PreventNavigation" KeyboardCloseEnabled="ComponentDialog.Options.KeyboardCloseEnabled"
1212
KeyboardCloseKey="@ComponentDialog.Options.KeyboardCloseKey">
1313
<DynamicComponent Type="ComponentDialog.Options.ComponentType" Parameters="ComponentDialog.Options.Parameters"></DynamicComponent>
@@ -17,8 +17,8 @@
1717
{
1818
<Dialog Id="@Key" IsCustom="ComponentDialog.Options.IsCustom"
1919
OnAfterRender="EventUtil.AsNonRenderingEventCallback((bool firstLoad) => OnAfterDialogRender(firstLoad))"
20-
OnAfterHide="ComponentDialog.Options.OnAfterHide" OnAfterShow="ComponentDialog.Options.OnAfterShow"
21-
OnBeforeHide="ComponentDialog.Options.OnBeforeHide" OnBeforeShow="ComponentDialog.Options.OnBeforeShow"
20+
OnAfterHide="ComponentDialog.Options.OnAfterHide!" OnAfterShow="ComponentDialog.Options.OnAfterShow!"
21+
OnBeforeHide="ComponentDialog.Options.OnBeforeHide!" OnBeforeShow="ComponentDialog.Options.OnBeforeShow!"
2222
PreventNavigation="ComponentDialog.Options.PreventNavigation" KeyboardCloseEnabled="ComponentDialog.Options.KeyboardCloseEnabled"
2323
KeyboardCloseKey="@ComponentDialog.Options.KeyboardCloseKey">
2424
<DynamicComponent Type="ComponentDialog.Options.ComponentType" Parameters="ComponentDialog.Options.Parameters"></DynamicComponent>
@@ -27,8 +27,8 @@
2727
</CascadingValue>
2828

2929
@code {
30-
[Parameter, EditorRequired] public ComponentDialog ComponentDialog { get; set; }
31-
[Parameter, EditorRequired] public string Key { get; set; }
30+
[Parameter, EditorRequired] public ComponentDialog ComponentDialog { get; set; } = null!;
31+
[Parameter, EditorRequired] public string Key { get; set; } = null!;
3232

3333
protected override void OnInitialized()
3434
{

BlazorDialog/Components/Dialog.razor

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
@code{
3030

31-
[Parameter] public RenderFragment ChildContent { get; set; }
31+
[Parameter] public RenderFragment ChildContent { get; set; } = null!;
3232

3333
/// <summary>
3434
/// The unique idetifier of the dialog. This field is required when using the dialog as a service.
3535
/// </summary>
36-
[Parameter] public string Id { get; set; }
36+
[Parameter] public string? Id { get; set; }
3737

3838
/// <summary>
3939
/// The base z-index of the dialog when shown. Default: 1050
@@ -44,6 +44,11 @@
4444
/// Use this to show/hide the dialog as a simple component.
4545
/// </summary>
4646
[Parameter] public bool? IsShowing { get; set; }
47+
48+
/// <summary>
49+
/// Used for two-way binding of the <see cref="IsShowing" /> parameter.
50+
/// </summary>
51+
[Parameter] public EventCallback<bool?> IsShowingChanged { get; set; }
4752
private bool isShowing;
4853

4954
/// <summary>
@@ -94,7 +99,7 @@
9499
/// <summary>
95100
/// Adds a custom css class to the wrapper of the dialog.
96101
/// </summary>
97-
[Parameter] public string CssClass { get; set; }
102+
[Parameter] public string? CssClass { get; set; }
98103

99104
/// <summary>
100105
/// An event that is triggered after the dialog renders.
@@ -118,11 +123,18 @@
118123

119124

120125
private bool? _forcedPreventNavigation;
121-
protected TaskCompletionSource<object> taskCompletionSource;
122-
internal Action<object> OnDialogHide;
126+
protected TaskCompletionSource<object?>? taskCompletionSource;
127+
internal Action<object?> OnDialogHide = null!;
123128
private DotNetObjectReference<Dialog>? dotNetObjectReference;
124129

125-
protected void NotifyDialogHidden(object result) => OnDialogHide?.Invoke(result);
130+
protected async Task NotifyDialogHidden(object? result)
131+
{
132+
OnDialogHide?.Invoke(result);
133+
if(IsShowingChanged.HasDelegate)
134+
{
135+
await IsShowingChanged.InvokeAsync(false);
136+
}
137+
}
126138

127139
protected string ContentWrapperCssClass
128140
{
@@ -175,7 +187,7 @@
175187
{
176188
dialogStore.Register(this);
177189
}
178-
OnDialogHide = (object result) =>
190+
OnDialogHide = (object? result) =>
179191
{
180192
if (taskCompletionSource != null)
181193
{
@@ -219,13 +231,13 @@
219231
locationChangingHandler.RemoveLocationChangingHandler(this);
220232
if (OnBeforeHide.HasDelegate)
221233
{
222-
var args = new DialogBeforeHideEventArgs(this);
234+
var args = new DialogBeforeHideEventArgs(this, default, triggeredFromKeyboard: false, triggeredFromCloseButton: false);
223235
await OnBeforeHide.InvokeAsync(args);
224236
}
225237
this.isShowing = false;
226238
if (OnAfterHide.HasDelegate)
227239
{
228-
var args = new DialogAfterHideEventArgs(this);
240+
var args = new DialogAfterHideEventArgs(this, triggeredFromKeyboard: false, triggeredFromCloseButton: false);
229241
await OnAfterHide.InvokeAsync(args);
230242
}
231243

@@ -266,7 +278,7 @@
266278
await this.Show<object>(input);
267279
}
268280

269-
public async Task<TResult?> Show<TResult>(object input)
281+
public async Task<TResult?> Show<TResult>(object? input)
270282
{
271283
this.Input = input;
272284
var result = await ShowInternal();
@@ -298,31 +310,47 @@
298310

299311
await jsRuntime.InvokeVoidAsync("blazorDialog.registerShownDialog", dotNetObjectReference, this.KeyboardCloseEnabled, this.KeyboardCloseKey);
300312

301-
taskCompletionSource = new TaskCompletionSource<object>();
313+
taskCompletionSource = new TaskCompletionSource<object?>();
302314
return await taskCompletionSource.Task;
303315
}
304316

305317

306-
public async Task Hide<TResult>(TResult result)
318+
public async Task Hide<TResult>(TResult? result)
319+
{
320+
await Hide(result, triggeredFromKeyboard: false, triggeredFromCloseButton: false);
321+
}
322+
323+
protected async Task Hide<TResult>(TResult? result, bool triggeredFromKeyboard = false, bool triggeredFromCloseButton = false)
307324
{
308-
locationChangingHandler.RemoveLocationChangingHandler(this);
309325
if (OnBeforeHide.HasDelegate)
310326
{
311-
var args = new DialogBeforeHideEventArgs(this);
327+
var args = new DialogBeforeHideEventArgs(this, result, triggeredFromKeyboard, triggeredFromCloseButton);
312328
await OnBeforeHide.InvokeAsync(args);
329+
if (args.PreventHide) return;
313330
}
331+
locationChangingHandler.RemoveLocationChangingHandler(this);
314332
this.isShowing = false;
315-
NotifyDialogHidden(result);
333+
await NotifyDialogHidden(result);
316334
await InvokeAsync(() => StateHasChanged());
317335
if (OnAfterHide.HasDelegate)
318336
{
319-
var args = new DialogAfterHideEventArgs(this);
337+
var args = new DialogAfterHideEventArgs(this, triggeredFromKeyboard, triggeredFromCloseButton);
320338
await OnAfterHide.InvokeAsync(args);
321339
}
322340

323341
await jsRuntime.InvokeVoidAsync("blazorDialog.unregisterShownDialog", dotNetObjectReference);
324342
}
325343

344+
internal async Task HideFromKeyboard()
345+
{
346+
await this.Hide<object>(null, triggeredFromKeyboard: true);
347+
}
348+
349+
internal async Task HideFromCloseButton()
350+
{
351+
await this.Hide<object>(null, triggeredFromCloseButton: true);
352+
}
353+
326354
public async Task Hide()
327355
{
328356
await this.Hide<object>(null);
@@ -367,6 +395,6 @@
367395
[JSInvokable]
368396
public async Task HideFromKeyPress()
369397
{
370-
await this.Hide();
398+
await this.HideFromKeyboard();
371399
}
372400
}

BlazorDialog/Components/DialogBody.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@code{
77

8-
[Parameter] public RenderFragment ChildContent { get; set; }
8+
[Parameter] public RenderFragment ChildContent { get; set; } = null!;
99

10-
[Parameter] public string CssClass { get; set; }
10+
[Parameter] public string? CssClass { get; set; }
1111
}

BlazorDialog/Components/DialogFooter.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
</div>
55

66
@code{
7-
[Parameter] public RenderFragment ChildContent { get; set; }
8-
[Parameter] public string CssClass { get; set; }
7+
[Parameter] public RenderFragment ChildContent { get; set; } = null!;
8+
[Parameter] public string? CssClass { get; set; }
99
}

BlazorDialog/Components/DialogHeader.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
</div>
1111

1212
@code{
13-
[Parameter] public RenderFragment ChildContent { get; set; }
13+
[Parameter] public RenderFragment ChildContent { get; set; } = null!;
1414
[Parameter] public bool ShowClose { get; set; } = false;
15-
[Parameter] public string CssClass { get; set; }
16-
[CascadingParameter(Name = "ParentDialog")] Dialog Dialog { get; set; }
15+
[Parameter] public string? CssClass { get; set; }
16+
[CascadingParameter(Name = "ParentDialog")] Dialog Dialog { get; set; } = null!;
1717

1818
private async Task OnCloseClick()
1919
{
20-
await Dialog.Hide();
20+
await Dialog.HideFromCloseButton();
2121
}
2222
}

BlazorDialog/Components/DialogInputProvider.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@ChildContent(new DialogContext<TInput>(ParentDialog, (TInput)Input))
55

66
@code{
7-
[Parameter] public RenderFragment<DialogContext<TInput>> ChildContent { get; set; }
8-
[CascadingParameter(Name = "DialogInput")] protected object Input { get; set; }
9-
[CascadingParameter(Name = "ParentDialog")] protected Dialog ParentDialog { get; set; }
7+
[Parameter] public RenderFragment<DialogContext<TInput>> ChildContent { get; set; } = null!;
8+
[CascadingParameter(Name = "DialogInput")] protected object Input { get; set; } = null!;
9+
[CascadingParameter(Name = "ParentDialog")] protected Dialog ParentDialog { get; set; } = null!;
1010
}

BlazorDialog/EventArgs.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,48 @@ public DialogAfterShowEventArgs(Dialog dialog) : base(dialog)
3232

3333
public class DialogBeforeHideEventArgs : DialogEventArgs
3434
{
35-
public DialogBeforeHideEventArgs(Dialog dialog) : base(dialog)
35+
public DialogBeforeHideEventArgs(Dialog dialog, object? result, bool triggeredFromKeyboard, bool triggeredFromCloseButton) : base(dialog)
3636
{
37+
Result = result;
38+
TriggeredFromKeyboard = triggeredFromKeyboard;
39+
TriggeredFromCloseButton = triggeredFromCloseButton;
3740
}
3841

39-
//public bool PreventHide { get; set; }
42+
/// <summary>
43+
/// If set to true, the dialog hide action will be prevented.
44+
/// </summary>
45+
public bool PreventHide { get; set; }
46+
47+
/// <summary>
48+
/// The dialog result if any.
49+
/// </summary>
50+
public object? Result { get; }
51+
52+
/// <summary>
53+
/// Gets a value indicating whether the action was triggered by a keyboard input.
54+
/// </summary>
55+
public bool TriggeredFromKeyboard { get; }
56+
57+
/// <summary>
58+
/// Gets a value indicating whether the action was triggered by the close button.
59+
/// </summary>
60+
public bool TriggeredFromCloseButton { get; }
4061
}
4162

4263
public class DialogAfterHideEventArgs : DialogEventArgs
4364
{
44-
public DialogAfterHideEventArgs(Dialog dialog) : base(dialog)
65+
public DialogAfterHideEventArgs(Dialog dialog, bool triggeredFromKeyboard, bool triggeredFromCloseButton) : base(dialog)
4566
{
67+
TriggeredFromKeyboard = triggeredFromKeyboard;
68+
TriggeredFromCloseButton = triggeredFromCloseButton;
4669
}
70+
/// <summary>
71+
/// Gets a value indicating whether the action was triggered by a keyboard input.
72+
/// </summary>
73+
public bool TriggeredFromKeyboard { get; }
74+
/// <summary>
75+
/// Gets a value indicating whether the action was triggered by the close button.
76+
/// </summary>
77+
public bool TriggeredFromCloseButton { get; }
4778
}
4879
}

0 commit comments

Comments
 (0)