From 23a50fb89d6270d72aecef29811ea60931c9a75f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Jan 2025 12:41:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(Drawer):=20=E5=A2=9E=E5=8A=A0=20BodyCo?= =?UTF-8?q?ntext=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Drawer/Drawer.razor | 6 ++++-- src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs | 6 ++++++ src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs | 4 ++++ src/BootstrapBlazor/Components/Drawer/DrawerOption.cs | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) 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; } } From 12b407174b2d12348cacaff63a7ec5c743f74861 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Jan 2025 12:41:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/DrawerTest.cs | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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(); + } } From 3972bef5cf7cb19554a3751deb6b9d38c329b218 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Jan 2025 17:05:57 +0800 Subject: [PATCH 3/4] chore: bump version 9.2.8-beta02 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From bf02eb35c97470c665aeaa3cb33881e15445fb57 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 15 Jan 2025 17:12:29 +0800 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/DrawerServiceTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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();