Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>9.3.1-beta04</Version>
<Version>9.3.1-beta05</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ else
<Checkbox TValue="bool" IsDisabled="GetDisabledState(item)"
ShowAfterLabel="true" ShowLabel="false" ShowLabelTooltip="ShowLabelTooltip"
DisplayText="@item.Text" OnBeforeStateChanged="_onBeforeStateChangedCallback!"
Value="@item.Active" OnStateChanged="@((_, v) => OnStateChanged(item, v))"></Checkbox>
Value="@item.Active" OnStateChanged="@((_, v) => OnStateChanged(item, v))"
ChildContent="GetChildContent(item)"></Checkbox>
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public partial class CheckboxListGeneric<TValue> : IModelEqualityComparer<TValue
[Parameter]
public Func<Task>? OnMaxSelectedCountExceed { get; set; }

/// <summary>
/// 获得/设置 项模板
/// </summary>
[Parameter]
public RenderFragment<SelectedItem<TValue>>? ItemTemplate { get; set; }

/// <summary>
/// 获得 当前选项是否被禁用
/// </summary>
Expand Down Expand Up @@ -216,6 +222,10 @@ private async Task OnStateChanged(SelectedItem<TValue> item, bool v)
/// </summary>
private Task OnClick(SelectedItem<TValue> item) => OnStateChanged(item, !item.Active);

private RenderFragment? GetChildContent(SelectedItem<TValue> item) => ItemTemplate == null
? null
: ItemTemplate(item);

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions test/UnitTest/Components/CheckboxListGenericTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@ await cut.InvokeAsync(async () =>
Assert.False(max);
}

[Fact]
public void ItemTemplate_Ok()
{
var items = new List<SelectedItem<Foo>>()
{
new(new Foo() { Id = 1, Name = "Test1" }, "Test 1"),
new(new Foo() { Id = 2, Name = "Test2" }, "Test 2"),
new(new Foo() { Id = 3, Name = "Test3" }, "Test 3")
};
var cut = Context.RenderComponent<CheckboxListGeneric<Foo>>(pb =>
{
pb.Add(a => a.Items, items);
pb.Add(a => a.ItemTemplate, foo => builder =>
{
builder.AddContent(0, foo.Text);
});
});
var labels = cut.FindAll(".checkbox-item .form-check-label");
Assert.Equal(3, labels.Count);
}

private class Dummy
{
[Required]
Expand Down