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;
}
}
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..ac3c1e1682c
--- /dev/null
+++ b/src/BootstrapBlazor/Components/Label/BootstrapLabelSetting.razor.cs
@@ -0,0 +1,24 @@
+// 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; }
+
+ ///
+ /// 获得/设置 标签宽度 默认 null 未设置使用全局设置 --bb-row-label-width
值
+ ///
+ [Parameter]
+ public int? LabelWidth { get; set; }
+}
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);
+ }
+}