From 76e5cf578889718e2bec6273b7155b15fb6f3331 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 07:50:38 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20AddStyle=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Utils/CssBuilder.cs | 66 ++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Utils/CssBuilder.cs b/src/BootstrapBlazor/Utils/CssBuilder.cs index d0b744099bb..a67669c64d9 100644 --- a/src/BootstrapBlazor/Utils/CssBuilder.cs +++ b/src/BootstrapBlazor/Utils/CssBuilder.cs @@ -106,7 +106,71 @@ public CssBuilder AddClassFromAttributes(IDictionary? additional } /// - /// Adds a conditional Style when it exists in a dictionary to the builder with space separator. + /// Adds a raw string to the builder that will be concatenated with the next style or value added to the builder. + /// + /// style property name + /// CSS style to conditionally add. + /// CssBuilder + public CssBuilder AddStyle(string key, string? value) + { + if (!string.IsNullOrEmpty(value)) stringBuffer.Add($"{key}: {value};"); + return this; + } + + /// + /// Adds a conditional css Style to the builder with space separator. + /// + /// style property name + /// CSS style to conditionally add. + /// Condition in which the CSS style is added. + /// CssBuilder + public CssBuilder AddStyle(string key, string? value, bool when = true) => when ? AddStyle(key, value) : this; + + /// + /// Adds a conditional css Style to the builder with space separator. + /// + /// style property name + /// CSS style to conditionally add. + /// Condition in which the CSS Style is added. + /// CssBuilder + public CssBuilder AddStyle(string key, string? value, Func when) => AddStyle(key, value, when()); + + /// + /// Adds a conditional css Style to the builder with space separator. + /// + /// style property name + /// Function that returns a css Style to conditionally add. + /// Condition in which the CSS Style is added. + /// CssBuilder + public CssBuilder AddStyle(string key, Func value, bool when = true) => when ? AddStyle(key, value()) : this; + + /// + /// Adds a conditional css Style to the builder with space separator. + /// + /// style property name + /// Function that returns a css Style to conditionally add. + /// Condition in which the CSS Style is added. + /// CssBuilder + public CssBuilder AddStyle(string key, Func value, Func when) => AddStyle(key, value, when()); + + /// + /// Adds a conditional nested CssBuilder to the builder with space separator. + /// + /// CSS Style to conditionally add. + /// Condition in which the CSS Style is added. + /// CssBuilder + public CssBuilder AddStyle(CssBuilder builder, bool when = true) => when ? AddClass(builder.Build()) : this; + + /// + /// Adds a conditional CSS Class to the builder with space separator. + /// + /// CSS Class to conditionally add. + /// Condition in which the CSS Class is added. + /// CssBuilder + public CssBuilder AddStyle(CssBuilder builder, Func when) => AddClass(builder, when()); + + /// + /// Adds a conditional css Style when it exists in a dictionary to the builder with space separator. /// Null safe operation. /// /// Additional Attribute splat parameters From 52235802c320447c377e662f7d9af183f79fbde1 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 07:50:45 +0800 Subject: [PATCH 02/10] =?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/Utils/CssBuilderTest.cs | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/UnitTest/Utils/CssBuilderTest.cs b/test/UnitTest/Utils/CssBuilderTest.cs index ebaf19063f9..27c02e19955 100644 --- a/test/UnitTest/Utils/CssBuilderTest.cs +++ b/test/UnitTest/Utils/CssBuilderTest.cs @@ -21,6 +21,51 @@ public void AddClass_When() Assert.Contains("cls_test", classString); } + [Fact] + public void AddStyle_When() + { + var classString = CssBuilder.Default() + .AddStyle("width", () => "cls_test", () => false) + .Build(); + Assert.DoesNotContain("widht: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", () => "cls_test", false) + .Build(); + Assert.DoesNotContain("widht: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", "cls_test", false) + .Build(); + Assert.DoesNotContain("widht: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", () => "cls_test", () => true) + .Build(); + Assert.Contains("width: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", () => "cls_test", true) + .Build(); + Assert.Contains("width: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", "cls_test", true) + .Build(); + Assert.Contains("width: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", "cls_test", () => true) + .Build(); + Assert.Contains("width: cls_test;", classString); + + classString = CssBuilder.Default() + .AddStyle("width", "cls_test_width") + .AddStyle("height", "cls_test_height") + .Build(); + Assert.Equal("width: cls_test_width; height: cls_test_height;", classString); + } + [Fact] public void AddClass_Builder() { @@ -37,6 +82,27 @@ public void AddClass_Builder() Assert.Contains("cls_test", classString); } + [Fact] + public void AddStyle_Builder() + { + var builder = CssBuilder.Default("width: cls_test_width;"); + + var classString = CssBuilder.Default() + .AddStyle(builder, false) + .Build(); + Assert.DoesNotContain("width: cls_test_width;", classString); + + classString = CssBuilder.Default() + .AddStyle(builder, () => true) + .Build(); + Assert.Contains("width: cls_test_width;", classString); + + classString = CssBuilder.Default() + .AddStyle(builder, true) + .Build(); + Assert.Contains("width: cls_test_width;", classString); + } + [Fact] public void AddStyleFromAttributes_Ok() { From 45fc876fbfeb9d935e1013e067e8722ef97295e6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 07:51:28 +0800 Subject: [PATCH 03/10] refactor: use AddStyle method --- src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs | 2 +- src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs | 2 +- .../Components/ValidateForm/ValidateForm.razor.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs index 356c7668eec..74d67201214 100644 --- a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs +++ b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs @@ -50,7 +50,7 @@ public partial class EditorForm : IShowLabel .Build(); private string? FormStyleString => CssBuilder.Default() - .AddClass($"--bb-row-label-width: {LabelWidth}px;", LabelWidth.HasValue) + .AddStyle("--bb-row-label-width", $"{LabelWidth}px", LabelWidth.HasValue) .Build(); /// diff --git a/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs b/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs index 9de80e6afd4..d5d7608f38d 100644 --- a/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs +++ b/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs @@ -36,7 +36,7 @@ public partial class BootstrapLabel .Build(); private string? StyleString => CssBuilder.Default() - .AddClass($"--bb-row-label-width: {LabelWidth}px;", LabelWidth.HasValue) + .AddStyle($"--bb-row-label-width", $"{LabelWidth}px", LabelWidth.HasValue) .Build(); /// diff --git a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs index 8d5fd93bb19..5333e8be2b4 100644 --- a/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs +++ b/src/BootstrapBlazor/Components/ValidateForm/ValidateForm.razor.cs @@ -131,7 +131,7 @@ public partial class ValidateForm private string? ShowAllInvalidResultString => ShowAllInvalidResult ? "true" : null; private string? StyleString => CssBuilder.Default() - .AddClass($"--bb-row-label-width: {LabelWidth}px;", LabelWidth.HasValue) + .AddStyle("--bb-row-label-width", $"{LabelWidth}px", LabelWidth.HasValue) .Build(); /// From 1043fb267490795f6a87a89db06ec45d159aeb82 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 07:55:58 +0800 Subject: [PATCH 04/10] =?UTF-8?q?doc:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Affix/Affix.razor.cs | 4 ++-- src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs index d4905fa9460..bd5e4606755 100644 --- a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs +++ b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs @@ -40,8 +40,8 @@ public partial class Affix .Build(); private string? StyleString => CssBuilder.Default("position: sticky;") - .AddClass($"z-index: {ZIndex};", ZIndex.HasValue) - .AddClass($"{Position.ToDescriptionString()}: {Offset}px;") + .AddStyle("z-index", $"{ZIndex}", ZIndex.HasValue) + .AddStyle($"{Position.ToDescriptionString()}", $"{Offset}px") .AddStyleFromAttributes(AdditionalAttributes) .Build(); } diff --git a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs index d426c02d434..13ff538f54a 100644 --- a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs +++ b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs @@ -20,15 +20,15 @@ public partial class Captcha /// 获得 组件宽度 /// private string? StyleString => CssBuilder.Default() - .AddClass($"width: {Width + 42}px;", Width > 0) + .AddStyle("width", $"{Width + 42}px", Width > 0) .Build(); /// /// 获得 加载图片失败样式 /// private string? FailedStyle => CssBuilder.Default() - .AddClass($"width: {Width}px;", Width > 0) - .AddClass($"height: {Height}px;", Height > 0) + .AddStyle("width", $"{Width}px", Width > 0) + .AddStyle("height", $"{Height}px", Height > 0) .Build(); /// From 37653dc4f1752f41e20b34745cda383c295fdcde Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 08:01:32 +0800 Subject: [PATCH 05/10] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index dceccd69e83..cf3e86aba3a 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -19,7 +19,7 @@ public partial class Drawer .Build(); private string? StyleString => CssBuilder.Default() - .AddClass($"--bb-drawer-position: {Position};", !string.IsNullOrEmpty(Position)) + .AddStyle("--bb-drawer-position", $"{Position}", !string.IsNullOrEmpty(Position)) .AddStyleFromAttributes(AdditionalAttributes) .Build(); @@ -27,8 +27,8 @@ public partial class Drawer /// 获得 抽屉 Style 字符串 /// private string? DrawerStyleString => CssBuilder.Default() - .AddClass($"--bb-drawer-width: {Width};", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) - .AddClass($"--bb-drawer-height: {Height};", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) + .AddStyle("--bb-drawer-width", $"{Width}", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) + .AddStyle("--bb-drawer-height", $"{Height}", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) .Build(); /// From ddd73c8e8f465ab172882baf43b14d10b3267bc0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 09:35:44 +0800 Subject: [PATCH 06/10] =?UTF-8?q?Revert=20"refactor:=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 37653dc4f1752f41e20b34745cda383c295fdcde. --- src/BootstrapBlazor/Components/Affix/Affix.razor.cs | 4 ++-- src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs | 6 +++--- src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs index bd5e4606755..d4905fa9460 100644 --- a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs +++ b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs @@ -40,8 +40,8 @@ public partial class Affix .Build(); private string? StyleString => CssBuilder.Default("position: sticky;") - .AddStyle("z-index", $"{ZIndex}", ZIndex.HasValue) - .AddStyle($"{Position.ToDescriptionString()}", $"{Offset}px") + .AddClass($"z-index: {ZIndex};", ZIndex.HasValue) + .AddClass($"{Position.ToDescriptionString()}: {Offset}px;") .AddStyleFromAttributes(AdditionalAttributes) .Build(); } diff --git a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs index 13ff538f54a..d426c02d434 100644 --- a/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs +++ b/src/BootstrapBlazor/Components/Captcha/Captcha.razor.cs @@ -20,15 +20,15 @@ public partial class Captcha /// 获得 组件宽度 /// private string? StyleString => CssBuilder.Default() - .AddStyle("width", $"{Width + 42}px", Width > 0) + .AddClass($"width: {Width + 42}px;", Width > 0) .Build(); /// /// 获得 加载图片失败样式 /// private string? FailedStyle => CssBuilder.Default() - .AddStyle("width", $"{Width}px", Width > 0) - .AddStyle("height", $"{Height}px", Height > 0) + .AddClass($"width: {Width}px;", Width > 0) + .AddClass($"height: {Height}px;", Height > 0) .Build(); /// diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index cf3e86aba3a..dceccd69e83 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -19,7 +19,7 @@ public partial class Drawer .Build(); private string? StyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-position", $"{Position}", !string.IsNullOrEmpty(Position)) + .AddClass($"--bb-drawer-position: {Position};", !string.IsNullOrEmpty(Position)) .AddStyleFromAttributes(AdditionalAttributes) .Build(); @@ -27,8 +27,8 @@ public partial class Drawer /// 获得 抽屉 Style 字符串 /// private string? DrawerStyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-width", $"{Width}", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) - .AddStyle("--bb-drawer-height", $"{Height}", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) + .AddClass($"--bb-drawer-width: {Width};", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) + .AddClass($"--bb-drawer-height: {Height};", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) .Build(); /// From a17cd7fe5652bb2fdb4c9418a9eb11fb01275f9c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 08:17:44 +0800 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20BootstrapLab?= =?UTF-8?q?elSetting=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Label/BootstrapLabelSetting.razor | 5 +++++ .../Label/BootstrapLabelSetting.razor.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor create mode 100644 src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs diff --git a/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor new file mode 100644 index 00000000000..a1d2d1a2123 --- /dev/null +++ b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor @@ -0,0 +1,5 @@ +@namespace BootstrapBlazor.Components + + + @ChildContent + diff --git a/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs new file mode 100644 index 00000000000..3a03b3617d0 --- /dev/null +++ b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs @@ -0,0 +1,18 @@ +// 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; + +/// +/// BootstrapLabelSetting 组件类 +/// +public partial class BootstrapLabelSetting +{ + /// + /// 获得/设置 子组件 + /// + [Parameter] + public RenderFragment? ChildContent { get; set; } +} From 7b865482561e19ba8b45d32a17f370773b636a9b Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 08:44:33 +0800 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20LabelWidth?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Label/BootstrapLabelSetting.razor.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs index 3a03b3617d0..ac3c1e1682c 100644 --- a/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs +++ b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs @@ -15,4 +15,10 @@ public partial class BootstrapLabelSetting /// [Parameter] public RenderFragment? ChildContent { get; set; } + + /// + /// 获得/设置 标签宽度 默认 null 未设置使用全局设置 --bb-row-label-width 值 + /// + [Parameter] + public int? LabelWidth { get; set; } } From cd5d9e472bc19de6c563df19034fd2c729562131 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 09:21:38 +0800 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=20LabelWidth?= =?UTF-8?q?=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Label/BootstrapLabel.razor.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs b/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs index d5d7608f38d..8221930a009 100644 --- a/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs +++ b/src/BootstrapBlazor/Components/Label/BootstrapLabel.razor.cs @@ -29,6 +29,9 @@ public partial class BootstrapLabel [Parameter] public int? LabelWidth { get; set; } + [CascadingParameter] + private BootstrapLabelSetting? Setting { get; set; } + private bool _showTooltip; private string? ClassString => CssBuilder.Default("form-label") @@ -52,5 +55,8 @@ protected override void OnParametersSet() _showTooltip = ShowLabelTooltip.Value; } Value ??= ""; + + // 获得级联参数的 LabelWidth + LabelWidth ??= Setting?.LabelWidth; } } From 8c988be10575f956668b5d2bfcbd09e29a5b0fb4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Feb 2025 09:28:56 +0800 Subject: [PATCH 10/10] =?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 --- .../UnitTest/Components/BootstrapLabelTest.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/UnitTest/Components/BootstrapLabelTest.cs diff --git a/test/UnitTest/Components/BootstrapLabelTest.cs b/test/UnitTest/Components/BootstrapLabelTest.cs new file mode 100644 index 00000000000..9295034a7b5 --- /dev/null +++ b/test/UnitTest/Components/BootstrapLabelTest.cs @@ -0,0 +1,40 @@ +// 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 UnitTest.Components; + +public class BootstrapLabelTest : BootstrapBlazorTestBase +{ + [Fact] + public void BootstrapLabelSetting_LabelWidth_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.LabelWidth, 120); + pb.AddChildContent(); + }); + Assert.Equal("", cut.Markup); + + var label = cut.FindComponent(); + label.SetParametersAndRender(pb => + { + pb.Add(a => a.LabelWidth, 80); + }); + Assert.Equal("", cut.Markup); + } + + [Fact] + public void LabelWidth_Ok() + { + var cut = Context.RenderComponent(); + Assert.Equal("", cut.Markup); + + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.LabelWidth, 120); + }); + Assert.Equal("", cut.Markup); + } +}