Skip to content

Commit

Permalink
feat(Checkbox): auto set DisplayText when set ShowAfterLabel to true (#…
Browse files Browse the repository at this point in the history
…4334)

* feat(Checkbox): support ShowAfterLabel

* test: 增加单元测试

* test: 更新单元测试

* chore: bump version 8.9.3
  • Loading branch information
ArgoZhang authored Sep 20, 2024
1 parent 1ef1030 commit 9022b71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.9.3-beta02</Version>
<Version>8.9.3</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
1 change: 1 addition & 0 deletions src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected override void OnParametersSet()

if (ShowAfterLabel)
{
DisplayText ??= FieldIdentifier?.GetDisplayName();
ShowLabel = false;
}

Expand Down
13 changes: 10 additions & 3 deletions test/UnitTest/Components/CheckboxListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ public void ShowAfterLabel_Ok()
var cut = Context.RenderComponent<Checkbox<string>>(builder =>
{
builder.Add(a => a.ShowAfterLabel, true);
builder.Add(a => a.DisplayText, "Test");
});
var label = cut.Find("label");
label.MarkupMatches("<label class=\"form-check-label\" diff:ignore>Test</label>");
cut.MarkupMatches("<div class=\"form-check\"><input class=\"form-check-input\" type=\"checkbox\" diff:ignore /></div>");

cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.ShowLabelTooltip, true);
pb.Add(a => a.DisplayText, "Test");
});

var span = cut.Find("span");
Expand Down Expand Up @@ -116,9 +115,17 @@ public void EditorForm_Ok()
pb.Add(a => a.Value, foo.Hobby);
pb.Add(a => a.ValueExpression, foo.GenerateValueExpression(nameof(foo.Hobby), typeof(IEnumerable<string>)));
});
builder.AddChildContent<Checkbox<bool>>(pb =>
{
pb.Add(a => a.ShowLabel, false);
pb.Add(a => a.ShowAfterLabel, true);
pb.Add(a => a.Value, foo.Complete);
pb.Add(a => a.ValueExpression, foo.GenerateValueExpression(nameof(foo.Complete), typeof(bool)));
});
});
// 断言生成 CheckboxList
Assert.Contains("form-check is-label", cut.Markup);
cut.Contains("是/否");

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

0 comments on commit 9022b71

Please sign in to comment.