Skip to content

Commit 2faae1f

Browse files
committed
refactor: 精简代码
1 parent 2ba3fc8 commit 2faae1f

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed
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)