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.Server/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<html lang="en" data-bs-theme='light'>

<head>
<meta name="theme-color" content="#712cf9">
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="bootstrapblazor,bootstrap,blazor,wasm,webassembly,UI,netcore,web,assembly">
<meta name="description" content="基于 Bootstrap 风格的 Blazor UI 组件库,用于研发企业级中后台产品。">
<meta name="author" content="argo ([email protected])">
<meta name="theme-color" content="#712cf9">
<title>@Localizer["SiteTitle"]</title>
<base href="/" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits ValidateBase<List<TValue?>>
@inherits ValidateBase<List<TValue>>

@if (IsShowLabel)
{
Expand Down Expand Up @@ -29,7 +29,7 @@ else
<Checkbox TValue="bool" IsDisabled="GetDisabledState(item)"
ShowAfterLabel="true" ShowLabel="false" ShowLabelTooltip="ShowLabelTooltip"
DisplayText="@item.Text" OnBeforeStateChanged="_onBeforeStateChangedCallback!"
Value="@item.Active" OnStateChanged="@((state, v) => OnStateChanged(item, v))"></Checkbox>
Value="@item.Active" OnStateChanged="@((_, v) => OnStateChanged(item, v))"></Checkbox>
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class CheckboxListGeneric<TValue> : IModelEqualityComparer<TValue
/// <summary>
/// 获得 组件内部 Checkbox 项目样式
/// </summary>
protected string? CheckboxItemClassString => CssBuilder.Default("checkbox-item")
private string? CheckboxItemClassString => CssBuilder.Default("checkbox-item")
.AddClass(CheckboxItemClass)
.Build();

Expand Down Expand Up @@ -97,7 +97,7 @@ public partial class CheckboxListGeneric<TValue> : IModelEqualityComparer<TValue
/// 获得/设置 SelectedItemChanged 方法
/// </summary>
[Parameter]
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue?>, Task>? OnSelectedChanged { get; set; }
public Func<IEnumerable<SelectedItem<TValue>>, List<TValue>, Task>? OnSelectedChanged { get; set; }

/// <summary>
/// 获得/设置 最多选中数量
Expand Down Expand Up @@ -204,23 +204,23 @@ private async Task<bool> OnBeforeStateChanged(CheckboxState state)
private async Task OnStateChanged(SelectedItem<TValue> item, bool v)
{
item.Active = v;
var vals = new List<TValue?>();
var items = new List<TValue>();
if (Value != null)
{
vals.AddRange(Value);
items.AddRange(Value);
}

var val = vals.Find(i => IsEquals(item.Value));
var val = items.Find(i => Equals(item.Value, i));
if (v && val == null)
{
vals.Add(item.Value);
items.Add(item.Value);
}
else
{
vals.Remove(val);
items.Remove(val!);
}

CurrentValue = vals;
CurrentValue = items;

if (OnSelectedChanged != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected override void OnParametersSet()
var t = NullableUnderlyingType ?? typeof(TValue);
if (t.IsEnum && Items == null)
{
Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default, NullItemText) : null);
Items = t.ToSelectList<TValue>((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem<TValue>(default!, NullItemText) : null);
}

Items ??= [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ private async Task OnChange(ChangeEventArgs args)

if (item == null)
{
TValue? val = default;
TValue val = default!;
if (TextConvertToValueCallback != null)
{
val = await TextConvertToValueCallback(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnInitialized()
Container?.Add(ToSelectedItem());
}

private SelectedItem<TValue> ToSelectedItem() => new(Value, Text ?? "")
private SelectedItem<TValue> ToSelectedItem() => new(Value!, Text ?? "")
{
Active = Active,
GroupName = GroupName ?? "",
Expand Down
6 changes: 3 additions & 3 deletions src/BootstrapBlazor/Misc/SelectedItemOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class SelectedItem<T>
/// <summary>
/// 构造函数
/// </summary>
public SelectedItem() { }
public SelectedItem() { Value = default!; }

/// <summary>
/// 构造函数
/// </summary>
/// <param name="value"></param>
/// <param name="text"></param>
public SelectedItem(T? value, string text)
public SelectedItem(T value, string text)
{
Value = value;
Text = text;
Expand All @@ -34,7 +34,7 @@ public SelectedItem(T? value, string text)
/// <summary>
/// 获得/设置 选项值
/// </summary>
public T? Value { get; set; }
public T Value { get; set; }

/// <summary>
/// 获得/设置 是否选中
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Components/CheckboxListGenericTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public void IsVertical_Ok()
[Fact]
public async Task NullItem_Ok()
{
var items = new List<SelectedItem<Foo>>()
var items = new List<SelectedItem<Foo?>>()
{
new(null, "Select ..."),
new(new Foo() { Id = 2, Name = "Test2" }, "Test 2")
};
var cut = Context.RenderComponent<CheckboxListGeneric<Foo>>(pb =>
var cut = Context.RenderComponent<CheckboxListGeneric<Foo?>>(pb =>
{
pb.Add(a => a.Items, items);
});
Expand Down
Loading