diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index 748f88a50..9ef0a24b8 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -429,19 +429,6 @@ public partial class Table } } - /// - /// 在 EditMode 等于 EditForm 情况下,关闭 EditFrom - /// - public void CloseEditForm() - { - if (EditMode == EditMode.EditForm) - { - ShowAddForm = false; - ShowEditForm = false; - StateHasChanged(); - } - } - /// /// 保存数据方法 /// diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 87f2c0723..a5f5bf4e9 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -4041,6 +4041,57 @@ public class TableTest : TableTestBase } } + [Theory] + [InlineData(InsertRowMode.First)] + [InlineData(InsertRowMode.Last)] + public void OnAddAsync_IsTracking_Ok(InsertRowMode mode) + { + var localizer = Context.Services.GetRequiredService>(); + var items = Foo.GenerateFoo(localizer, 2); + var added = 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.IsTracking, true); + pb.Add(a => a.ShowExtendButtons, true); + pb.Add(a => a.EditMode, EditMode.EditForm); + pb.Add(a => a.InsertRowMode, mode); + pb.Add(a => a.OnAddAsync, () => + { + added = true; + return Task.FromResult(new Foo() { Name = "test" }); + }); + pb.Add(a => a.OnSaveAsync, (foo, changedType) => + { + return Task.FromResult(true); + }); + 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 add button + var button = cut.FindComponent>(); + cut.InvokeAsync(() => button.Instance.OnClick.InvokeAsync()); + Assert.True(added); + + var input = cut.Find("tbody form input"); + cut.InvokeAsync(() => input.Change("test_name")); + + var form = cut.Find("tbody form"); + cut.InvokeAsync(() => form.Submit()); + } + [Fact] public async Task OnEditAsync_Ok() { @@ -4648,8 +4699,10 @@ public class TableTest : TableTestBase Assert.Contains("fa-solid fa-xmark", table.Find("tbody").ToMarkup()); } - [Fact] - public async Task EditAsync_Ok() + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task EditAsync_Ok(bool isTracking) { var localizer = Context.Services.GetRequiredService>(); var items = Foo.GenerateFoo(localizer, 2); @@ -4662,6 +4715,7 @@ public class TableTest : TableTestBase pb.Add(a => a.Items, items); pb.Add(a => a.IsMultipleSelect, true); pb.Add(a => a.ShowToolbar, true); + pb.Add(a => a.IsTracking, isTracking); pb.Add(a => a.TableColumns, foo => builder => { builder.OpenComponent>(0);