feat(TableToolbarButton): support OnClickWithoutRender callback (#3911)

* feat: 增加 OnClickWithoutRender 方法支持

* test: 增加单元测试

* chore: bump version 8.7.4-beta05
This commit is contained in:
Argo Zhang
2024-07-23 14:47:10 +08:00
committed by GitHub
parent 336eee1a46
commit 6669adace7
3 changed files with 13 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>8.7.4-beta04</Version>
<Version>8.7.4-beta05</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

View File

@@ -61,6 +61,11 @@ public partial class TableToolbar<TItem> : ComponentBase
await button.OnClick.InvokeAsync();
}
if (button.OnClickWithoutRender != null)
{
await button.OnClickWithoutRender();
}
// 传递当前选中行给回调委托方法
if (button.OnClickCallback != null)
{

View File

@@ -2403,6 +2403,7 @@ public class TableTest : TableTestBase
{
var clicked = false;
var clickCallback = false;
var clickWithoutRender = false;
var selected = 0;
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
@@ -2429,6 +2430,11 @@ public class TableTest : TableTestBase
clickCallback = true;
return Task.CompletedTask;
}));
builder.AddAttribute(15, nameof(TableToolbarButton<Foo>.OnClickWithoutRender), new Func<Task>(() =>
{
clickWithoutRender = true;
return Task.CompletedTask;
}));
builder.AddAttribute(3, nameof(TableToolbarButton<Foo>.OnClick), EventCallback.Factory.Create<MouseEventArgs>(this, e =>
{
clicked = true;
@@ -2474,6 +2480,7 @@ public class TableTest : TableTestBase
await cut.InvokeAsync(() => button.Instance.OnClickWithoutRender!.Invoke());
Assert.True(clicked);
Assert.True(clickCallback);
Assert.True(clickWithoutRender);
// 选中一行
var input = cut.Find("tbody tr input");