!3553 feat(#I62FUO): add FirstAfterRenderCallbackAsync parameter on Modal

* doc: 更新文档
* test: 增加单元测试
* refactor: 更改回调名称
* chore: bump version 7.0.6-beta01
* feat: add FirstAfterRenderAsync callback
This commit is contained in:
Argo 2022-11-22 06:12:40 +00:00
parent f5eae00235
commit 6005989615
4 changed files with 42 additions and 5 deletions

View File

@ -79,6 +79,13 @@ public sealed partial class Modals
/// <returns></returns>
private static IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
new AttributeItem() {
Name = "FirstAfterRenderCallbackAsync",
Description = "Modal first after render callback",
Type = "Func<Task>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "HeaderTemplate",
Description = "Modal body ModalHeader template",

View File

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

View File

@ -47,12 +47,10 @@ public partial class Modal
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// 获得/设置 弹窗已显示时回调此方法
/// 获得/设置 组件已经渲染完毕回调方法
/// </summary>
[Parameter]
[Obsolete("Call OnShownAsync")]
[ExcludeFromCodeCoverage]
public Func<Task>? ShownCallbackAsync { get; set; }
public Func<Task>? FirstAfterRenderCallbackAsync { get; set; }
/// <summary>
/// 获得/设置 弹窗已显示时回调此方法
@ -73,6 +71,21 @@ public partial class Modal
private string? KeyboardString => IsKeyboard ? "true" : "false";
/// <summary>
/// <inheritdoc/>
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender && FirstAfterRenderCallbackAsync != null)
{
await FirstAfterRenderCallbackAsync();
}
}
/// <summary>
/// <inheritdoc/>
/// </summary>

View File

@ -97,6 +97,23 @@ public class ModalTest : BootstrapBlazorTestBase
Assert.True(cut.Instance.Value);
}
[Fact]
public async Task FirstAfterRenderAsync_Ok()
{
var render = false;
var cut = Context.RenderComponent<Modal>(pb =>
{
pb.Add(a => a.FirstAfterRenderCallbackAsync, () =>
{
render = true;
return Task.CompletedTask;
});
pb.AddChildContent<ModalDialog>();
});
Assert.True(render);
}
private class MockComponent : ComponentBase
{
public bool Value { get; set; }