Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ private Dictionary<string, object> 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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Drawer/DrawerOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class DrawerOption
/// </summary>
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// 获得/设置 自定义组件
/// </summary>
public BootstrapDynamicComponent? Component { get; set; }

/// <summary>
/// 获得/设置 是否允许调整大小 默认 false
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/BootstrapBlazor/Extensions/DrawerOptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -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([email protected]) Website: https://www.blazor.zone

namespace BootstrapBlazor.Components;

/// <summary>
/// <see cref="DrawerOption"/> 扩展方法
/// </summary>
public static class DrawerOptionExtensions
{
/// <summary>
/// 获得 组件渲染块
/// </summary>
/// <param name="drawerOption"></param>
/// <returns></returns>
public static RenderFragment? GetContent(this DrawerOption drawerOption) => drawerOption.ChildContent ?? drawerOption.Component?.Render();
}
12 changes: 11 additions & 1 deletion test/UnitTest/Services/DrawerServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DialogCloseButton>();
await service.Show(option);
button = cut.Find("button");
await cut.InvokeAsync(() => button.Click());

option.Component = null;
Assert.Null(option.GetContent());

await service.Show<DrawerDemo>();
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());
}
Expand Down
Loading