Skip to content

Commit df71110

Browse files
authored
feat(BootstrapInputGroupLabel): add ChildContent parameter (#5905)
* feat: 增加 ChildContent 模板 * test: 更新单元测试
1 parent 5420721 commit df71110

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/BootstrapBlazor/Components/Input/BootstrapInputGroupLabel.razor

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@
44
@if (IsInputGroupLabel)
55
{
66
<div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">
7-
<span>@DisplayText</span>
7+
@if (ChildContent != null)
8+
{
9+
@ChildContent
10+
}
11+
else
12+
{
13+
<span>@DisplayText</span>
14+
}
815
</div>
916
}
1017
else
1118
{
12-
<label @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" required="@Required">@DisplayText</label>
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>
1329
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public partial class BootstrapInputGroupLabel
4141
[Parameter]
4242
public bool ShowRequiredMark { get; set; }
4343

44+
/// <summary>
45+
/// Gets or sets the child content. Default is null.
46+
/// </summary>
47+
[Parameter]
48+
public RenderFragment? ChildContent { get; set; }
49+
4450
private string? Required => ShowRequiredMark ? "true" : null;
4551

4652
private bool IsInputGroupLabel => InputGroup != null;

test/UnitTest/Components/InputTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ public void GroupLabel_Ok()
273273
});
274274

275275
Assert.Contains("DisplayText", cut.Markup);
276+
277+
cut.SetParametersAndRender(pb =>
278+
{
279+
pb.Add(a => a.ChildContent, builder => builder.AddContent(0, "test-child-content"));
280+
});
281+
cut.Contains("test-child-content");
282+
cut.DoesNotContain("DisplayText");
276283
}
277284

278285
[Fact]

0 commit comments

Comments
 (0)