diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index fc08a80e21c..572d43e7f82 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -79,9 +79,10 @@ private Dictionary GetParameters(DrawerOption option) { parameters.Add(nameof(Drawer.Height), option.Height); } - if (option.ChildContent != null) + var content = option.GetContent(); + if (content != null) { - parameters.Add(nameof(Drawer.ChildContent), option.ChildContent); + parameters.Add(nameof(Drawer.ChildContent), content); } if (option.OnClickBackdrop != null) { diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs index 1d6e518a727..602447399d3 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -45,6 +45,11 @@ public class DrawerOption /// public RenderFragment? ChildContent { get; set; } + /// + /// 获得/设置 自定义组件 + /// + public BootstrapDynamicComponent? Component { get; set; } + /// /// 获得/设置 是否允许调整大小 默认 false /// diff --git a/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs b/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs new file mode 100644 index 00000000000..6fdc6a00171 --- /dev/null +++ b/src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +namespace BootstrapBlazor.Components; + +/// +/// 扩展方法 +/// +public static class DrawerOptionExtensions +{ + /// + /// 获得 组件渲染块 + /// + /// + /// + public static RenderFragment? GetContent(this DrawerOption drawerOption) => drawerOption.ChildContent ?? drawerOption.Component?.Render(); +} diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index 0391d0c0bb8..2360d0e7bc8 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -30,11 +30,21 @@ public async Task Show_Ok() var button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); + option.ChildContent = null; + option.Component = BootstrapDynamicComponent.CreateComponent(); + await service.Show(option); + button = cut.Find("button"); + await cut.InvokeAsync(() => button.Click()); + + option.Component = null; + Assert.Null(option.GetContent()); + await service.Show(); button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); - await service.Show(typeof(DrawerDemo)); + var type = typeof(DrawerDemo); + await service.Show(type); button = cut.Find("button"); await cut.InvokeAsync(() => button.Click()); }