Skip to content

Commit 9022b71

Browse files
authored
feat(Checkbox): auto set DisplayText when set ShowAfterLabel to true (#4334)
* feat(Checkbox): support ShowAfterLabel * test: 增加单元测试 * test: 更新单元测试 * chore: bump version 8.9.3
1 parent 1ef1030 commit 9022b71

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>8.9.3-beta02</Version>
4+
<Version>8.9.3</Version>
55
</PropertyGroup>
66

77
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected override void OnParametersSet()
118118

119119
if (ShowAfterLabel)
120120
{
121+
DisplayText ??= FieldIdentifier?.GetDisplayName();
121122
ShowLabel = false;
122123
}
123124

test/UnitTest/Components/CheckboxListTest.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ public void ShowAfterLabel_Ok()
3232
var cut = Context.RenderComponent<Checkbox<string>>(builder =>
3333
{
3434
builder.Add(a => a.ShowAfterLabel, true);
35-
builder.Add(a => a.DisplayText, "Test");
3635
});
37-
var label = cut.Find("label");
38-
label.MarkupMatches("<label class=\"form-check-label\" diff:ignore>Test</label>");
36+
cut.MarkupMatches("<div class=\"form-check\"><input class=\"form-check-input\" type=\"checkbox\" diff:ignore /></div>");
3937

4038
cut.SetParametersAndRender(pb =>
4139
{
4240
pb.Add(a => a.ShowLabelTooltip, true);
41+
pb.Add(a => a.DisplayText, "Test");
4342
});
4443

4544
var span = cut.Find("span");
@@ -116,9 +115,17 @@ public void EditorForm_Ok()
116115
pb.Add(a => a.Value, foo.Hobby);
117116
pb.Add(a => a.ValueExpression, foo.GenerateValueExpression(nameof(foo.Hobby), typeof(IEnumerable<string>)));
118117
});
118+
builder.AddChildContent<Checkbox<bool>>(pb =>
119+
{
120+
pb.Add(a => a.ShowLabel, false);
121+
pb.Add(a => a.ShowAfterLabel, true);
122+
pb.Add(a => a.Value, foo.Complete);
123+
pb.Add(a => a.ValueExpression, foo.GenerateValueExpression(nameof(foo.Complete), typeof(bool)));
124+
});
119125
});
120126
// 断言生成 CheckboxList
121127
Assert.Contains("form-check is-label", cut.Markup);
128+
cut.Contains("是/否");
122129

123130
// 提交表单触发客户端验证
124131
var form = cut.Find("form");

0 commit comments

Comments
 (0)