diff --git a/src/BootstrapBlazor.Server/Components/App.razor b/src/BootstrapBlazor.Server/Components/App.razor index 1f2ca968ed7..9aaf2be3020 100644 --- a/src/BootstrapBlazor.Server/Components/App.razor +++ b/src/BootstrapBlazor.Server/Components/App.razor @@ -6,7 +6,6 @@ - @@ -14,6 +13,7 @@ + @Localizer["SiteTitle"] diff --git a/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor b/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor index fe616025277..24ef73c5e39 100644 --- a/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor +++ b/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor @@ -1,6 +1,6 @@ @namespace BootstrapBlazor.Components @typeparam TValue -@inherits ValidateBase> +@inherits ValidateBase> @if (IsShowLabel) { @@ -29,7 +29,7 @@ else + Value="@item.Active" OnStateChanged="@((_, v) => OnStateChanged(item, v))"> } diff --git a/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs b/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs index 610fbea65f8..fae410213ff 100644 --- a/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs +++ b/src/BootstrapBlazor/Components/Checkbox/CheckboxListGeneric.razor.cs @@ -25,7 +25,7 @@ public partial class CheckboxListGeneric : IModelEqualityComparer /// 获得 组件内部 Checkbox 项目样式 /// - protected string? CheckboxItemClassString => CssBuilder.Default("checkbox-item") + private string? CheckboxItemClassString => CssBuilder.Default("checkbox-item") .AddClass(CheckboxItemClass) .Build(); @@ -97,7 +97,7 @@ public partial class CheckboxListGeneric : IModelEqualityComparer [Parameter] - public Func>, List, Task>? OnSelectedChanged { get; set; } + public Func>, List, Task>? OnSelectedChanged { get; set; } /// /// 获得/设置 最多选中数量 @@ -204,23 +204,23 @@ private async Task OnBeforeStateChanged(CheckboxState state) private async Task OnStateChanged(SelectedItem item, bool v) { item.Active = v; - var vals = new List(); + var items = new List(); 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) { diff --git a/src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs b/src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs index 72de2d18e48..833d8ddc863 100644 --- a/src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs +++ b/src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs @@ -120,7 +120,7 @@ protected override void OnParametersSet() var t = NullableUnderlyingType ?? typeof(TValue); if (t.IsEnum && Items == null) { - Items = t.ToSelectList((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem(default, NullItemText) : null); + Items = t.ToSelectList((NullableUnderlyingType != null && IsAutoAddNullItem) ? new SelectedItem(default!, NullItemText) : null); } Items ??= []; diff --git a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs index 62a3ee59e39..f026409bd72 100644 --- a/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs +++ b/src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs @@ -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); diff --git a/src/BootstrapBlazor/Components/SelectGeneric/SelectOptionGeneric.cs b/src/BootstrapBlazor/Components/SelectGeneric/SelectOptionGeneric.cs index 01299f97134..bacfdc85240 100644 --- a/src/BootstrapBlazor/Components/SelectGeneric/SelectOptionGeneric.cs +++ b/src/BootstrapBlazor/Components/SelectGeneric/SelectOptionGeneric.cs @@ -58,7 +58,7 @@ protected override void OnInitialized() Container?.Add(ToSelectedItem()); } - private SelectedItem ToSelectedItem() => new(Value, Text ?? "") + private SelectedItem ToSelectedItem() => new(Value!, Text ?? "") { Active = Active, GroupName = GroupName ?? "", diff --git a/src/BootstrapBlazor/Misc/SelectedItemOfT.cs b/src/BootstrapBlazor/Misc/SelectedItemOfT.cs index cb7bef8405f..9608ebdbd51 100644 --- a/src/BootstrapBlazor/Misc/SelectedItemOfT.cs +++ b/src/BootstrapBlazor/Misc/SelectedItemOfT.cs @@ -13,14 +13,14 @@ public class SelectedItem /// /// 构造函数 /// - public SelectedItem() { } + public SelectedItem() { Value = default!; } /// /// 构造函数 /// /// /// - public SelectedItem(T? value, string text) + public SelectedItem(T value, string text) { Value = value; Text = text; @@ -34,7 +34,7 @@ public SelectedItem(T? value, string text) /// /// 获得/设置 选项值 /// - public T? Value { get; set; } + public T Value { get; set; } /// /// 获得/设置 是否选中 diff --git a/test/UnitTest/Components/CheckboxListGenericTest.cs b/test/UnitTest/Components/CheckboxListGenericTest.cs index bf3cc5b70da..d6080b0a61e 100644 --- a/test/UnitTest/Components/CheckboxListGenericTest.cs +++ b/test/UnitTest/Components/CheckboxListGenericTest.cs @@ -78,12 +78,12 @@ public void IsVertical_Ok() [Fact] public async Task NullItem_Ok() { - var items = new List>() + var items = new List>() { new(null, "Select ..."), new(new Foo() { Id = 2, Name = "Test2" }, "Test 2") }; - var cut = Context.RenderComponent>(pb => + var cut = Context.RenderComponent>(pb => { pb.Add(a => a.Items, items); });