mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 21:50:05 +08:00
!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:
parent
f5eae00235
commit
6005989615
@ -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",
|
||||
|
@ -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'">
|
||||
|
@ -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>
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user