diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 7d583993fd3..665f76f8512 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.2.8-beta01 + 9.2.8-beta02 diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor b/src/BootstrapBlazor/Components/Drawer/Drawer.razor index b961a188935..1041573e9ce 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor @@ -10,8 +10,10 @@ }
- - @ChildContent + + + @ChildContent +
@if (AllowResize) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index 7e1e20448ba..5181b7e497e 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -113,6 +113,12 @@ public partial class Drawer [Parameter] public Func? OnCloseAsync { get; set; } + /// + /// 获得/设置 抽屉内容相关数据 多用于传值 + /// + [Parameter] + public object? BodyContext { get; set; } + /// /// /// diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs index 572d43e7f82..293d4422cc5 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs @@ -88,6 +88,10 @@ private Dictionary GetParameters(DrawerOption option) { parameters.Add(nameof(Drawer.OnClickBackdrop), option.OnClickBackdrop); } + if (option.BodyContext != null) + { + parameters.Add(nameof(Drawer.BodyContext), option.BodyContext); + } return parameters; } diff --git a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs index 602447399d3..b217640ca96 100644 --- a/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs +++ b/src/BootstrapBlazor/Components/Drawer/DrawerOption.cs @@ -64,4 +64,9 @@ public class DrawerOption /// 获得/设置 关闭当前 Drawer 回调委托 默认 null /// public Func? OnCloseAsync { get; set; } + + /// + /// 获得/设置 相关连数据,多用于传值使用 + /// + public object? BodyContext { get; set; } } diff --git a/test/UnitTest/Components/DrawerTest.cs b/test/UnitTest/Components/DrawerTest.cs index aaf8f299d79..8cb48b69b7a 100644 --- a/test/UnitTest/Components/DrawerTest.cs +++ b/test/UnitTest/Components/DrawerTest.cs @@ -106,6 +106,25 @@ public void ChildContent_Ok() Assert.NotNull(button); } + [Fact] + public void BodyContext_Ok() + { + var cut = Context.RenderComponent(builder => + { + builder.Add(a => a.BodyContext, "test-body-context"); + builder.Add(a => a.ChildContent, s => + { + s.OpenComponent(0); + s.CloseComponent(); + }); + }); + + var component = cut.FindComponent(); + Assert.NotNull(component); + + Assert.Equal("test-body-context", component.Instance.GetBodyContext()); + } + [Fact] public void ShowBackdrop_Ok() { @@ -141,4 +160,13 @@ public void Position_Ok() }); cut.Contains("--bb-drawer-position: absolute;"); } + + class MockContent : ComponentBase + { + [CascadingParameter(Name = "BodyContext")] + [NotNull] + private object? BodyContext { get; set; } + + public string? GetBodyContext() => BodyContext.ToString(); + } } diff --git a/test/UnitTest/Services/DrawerServiceTest.cs b/test/UnitTest/Services/DrawerServiceTest.cs index 2360d0e7bc8..4cbd9a36b42 100644 --- a/test/UnitTest/Services/DrawerServiceTest.cs +++ b/test/UnitTest/Services/DrawerServiceTest.cs @@ -22,7 +22,8 @@ public async Task Show_Ok() OnClickBackdrop = () => Task.CompletedTask, OnCloseAsync = () => Task.CompletedTask, Placement = Placement.Bottom, - ShowBackdrop = true + ShowBackdrop = true, + BodyContext = "test-body-context" }; var service = Context.Services.GetRequiredService(); var cut = Context.RenderComponent();