diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 99d0077a1cd..22686dd7d98 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.1.3-beta02 + 9.1.3-beta03 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index 94b729568f6..0a9c9ce9ad6 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -622,7 +622,7 @@ private async Task ShowDeleteToastAsync(string title, string content, ToastCateg /// 取消保存方法 /// /// - protected void CancelSave() + protected async Task CancelSave() { if (EditMode == EditMode.EditForm) { @@ -635,6 +635,11 @@ protected void CancelSave() AddInCell = false; EditInCell = false; } + + if (OnAfterCancelSaveAsync != null) + { + await OnAfterCancelSaveAsync(); + } } /// diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 936168feafb..b7d68df963d 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -5507,6 +5507,88 @@ public async Task OnSaveAsync_Ok() Assert.True(afterModify); } + [Fact] + public async Task OnAfterCancelSaveAsync_EditForm() + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer, 2); + var afterCancelSave = false; + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.Items, items); + pb.Add(a => a.IsMultipleSelect, true); + pb.Add(a => a.ShowToolbar, true); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.EditMode, EditMode.EditForm); + pb.Add(a => a.OnAfterCancelSaveAsync, () => + { + afterCancelSave = true; + return Task.CompletedTask; + }); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + // test edit button + var button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[0].Click()); + + // 取消按钮 + var cancelButton = cut.Find(".form-footer .btn-secondary"); + await cut.InvokeAsync(() => cancelButton.Click()); + Assert.True(afterCancelSave); + } + + [Fact] + public async Task OnAfterCancelSaveAsync_InCell() + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer, 2); + var afterCancelSave = false; + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.Items, items); + pb.Add(a => a.IsMultipleSelect, true); + pb.Add(a => a.ShowToolbar, true); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.EditMode, EditMode.EditForm); + pb.Add(a => a.OnAfterCancelSaveAsync, () => + { + afterCancelSave = true; + return Task.CompletedTask; + }); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + }); + }); + }); + + // test edit button + var button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[0].Click()); + + // 取消按钮 + button = cut.FindAll("tbody tr button"); + await cut.InvokeAsync(() => button[1].Click()); + Assert.True(afterCancelSave); + } + [Fact] public async Task OnAfterCancelSaveAsync_Popup() {