Skip to content

Commit 89d9077

Browse files
authored
refactor(BootstrapInputGroupLabel): use DynamicElement unified tag (#6101)
* refactor: 精简代码 * style: 代码格式化
1 parent 2ba3fc8 commit 89d9077

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

src/BootstrapBlazor/Components/Input/BootstrapInputGroup.razor.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.input-group {
1+
.input-group {
22
> .datetime-picker,
33
> .select,
44
> .switch,
Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
@namespace BootstrapBlazor.Components
22
@inherits DisplayBase<string>
33

4-
@if (IsInputGroupLabel)
5-
{
6-
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">
7-
@if (ChildContent != null)
8-
{
9-
@ChildContent
10-
}
11-
else
12-
{
13-
<span>@DisplayText</span>
14-
}
15-
</div>
16-
}
17-
else
18-
{
19-
<label @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">
20-
@if (ChildContent != null)
21-
{
22-
@ChildContent
23-
}
24-
else
25-
{
26-
@DisplayText
27-
}
28-
</label>
29-
}
4+
<DynamicElement @attributes="@AdditionalAttributes" TagName="@TagName" class="@ClassString" style="@StyleString" required="@Required">
5+
@if (ChildContent != null)
6+
{
7+
@ChildContent
8+
}
9+
else
10+
{
11+
@DisplayText
12+
}
13+
</DynamicElement>

src/BootstrapBlazor/Components/Input/BootstrapInputGroupLabel.razor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public partial class BootstrapInputGroupLabel
2323
.AddClassFromAttributes(AdditionalAttributes)
2424
.Build();
2525

26+
private string TagName => IsInputGroupLabel ? "div" : "label";
27+
2628
/// <summary>
2729
/// 获得/设置 标签宽度 默认 null 未设置自动适应
2830
/// </summary>

0 commit comments

Comments
 (0)