Skip to content

Commit ef3cf71

Browse files
committed
Merge branch 'dev-radio-list' into dev
# Conflicts: # src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs
2 parents 58b1918 + dd24781 commit ef3cf71

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/BootstrapBlazor.Server/Components/Samples/Radios.razor

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@
125125
</ValidateForm>
126126
</DemoBlock>
127127

128+
<DemoBlock Title="@Localizer["GenericTitle"]" Introduction="@Localizer["GenericIntro"]" Name="Generic">
129+
<RadioListGeneric @bind-Value="@_selectedFoo" Items="@GenericItems" />
130+
<section ignore>
131+
<div>@_selectedFoo.Name</div>
132+
</section>
133+
</DemoBlock>
134+
128135
<AttributeTable Items="@GetAttributes()" />
129136

130137
<EventTable Items="@GetEvents()" />

src/BootstrapBlazor.Server/Components/Samples/Radios.razor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using DocumentFormat.OpenXml.Office2010.Excel;
7+
using DocumentFormat.OpenXml.Wordprocessing;
8+
69
namespace BootstrapBlazor.Server.Components.Samples;
710

811
/// <summary>
@@ -52,6 +55,12 @@ private Task OnSelectedChanged(IEnumerable<SelectedItem> values, string val)
5255
return Task.CompletedTask;
5356
}
5457

58+
[NotNull]
59+
private IEnumerable<SelectedItem<Foo>>? GenericItems { get; set; }
60+
61+
[NotNull]
62+
private Foo? _selectedFoo = default;
63+
5564
/// <summary>
5665
/// OnInitialized 方法
5766
/// </summary>
@@ -85,6 +94,15 @@ protected override void OnInitialized()
8594

8695
Model = Foo.Generate(LocalizerFoo);
8796
FooItems = Foo.GetCompleteItems(LocalizerFoo);
97+
98+
GenericItems = new List<SelectedItem<Foo>>()
99+
{
100+
new() { Text = Localizer["item1"], Value = new Foo() { Id = 1, Name = LocalizerFoo["Foo.Name", "001"] } },
101+
new() { Text = Localizer["item2"], Value = new Foo() { Id = 2, Name = LocalizerFoo["Foo.Name", "002"] } },
102+
new() { Text = Localizer["item3"], Value = new Foo() { Id = 3, Name = LocalizerFoo["Foo.Name", "003"] } },
103+
};
104+
105+
_selectedFoo = new Foo() { Id = 1, Name = LocalizerFoo["Foo.Name", "001"] };
88106
}
89107

90108
private Task OnItemChanged(IEnumerable<SelectedItem> values, SelectedItem val)

src/BootstrapBlazor/Components/Radio/RadioListGeneric.razor.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public partial class RadioListGeneric<TValue> : IModelEqualityComparer<TValue>
2929
[Parameter]
3030
public RenderFragment<SelectedItem<TValue>>? ItemTemplate { get; set; }
3131

32+
/// <summary>
33+
/// 获得/设置 是否为按钮样式 默认 false
34+
/// </summary>
35+
[Parameter]
36+
public bool IsButton { get; set; }
37+
3238
/// <summary>
3339
/// 获得/设置 是否显示边框 默认为 true
3440
/// </summary>
@@ -58,7 +64,7 @@ public partial class RadioListGeneric<TValue> : IModelEqualityComparer<TValue>
5864
/// 获得/设置 SelectedItemChanged 方法
5965
/// </summary>
6066
[Parameter]
61-
public Func<IEnumerable<SelectedItem<TValue>>, TValue, Task>? OnSelectedChanged { get; set; }
67+
public Func<TValue, Task>? OnSelectedChanged { get; set; }
6268

6369
/// <summary>
6470
/// 获得/设置 数据主键标识标签 默认为 <see cref="KeyAttribute"/><code><br /></code>用于判断数据主键标签,如果模型未设置主键时可使用 <see cref="ModelEqualityComparer"/> 参数自定义判断 <code><br /></code>数据模型支持联合主键
@@ -74,6 +80,13 @@ public partial class RadioListGeneric<TValue> : IModelEqualityComparer<TValue>
7480
[Parameter]
7581
public Func<TValue, TValue, bool>? ModelEqualityComparer { get; set; }
7682

83+
/// <summary>
84+
/// 获得 当前选项是否被禁用
85+
/// </summary>
86+
/// <param name="item"></param>
87+
/// <returns></returns>
88+
private bool GetDisabledState(SelectedItem<TValue> item) => IsDisabled || item.IsDisabled;
89+
7790
private string? GroupName => Id;
7891

7992
private string? ClassString => CssBuilder.Default("radio-list form-control")
@@ -88,8 +101,8 @@ public partial class RadioListGeneric<TValue> : IModelEqualityComparer<TValue>
88101
.AddClassFromAttributes(AdditionalAttributes)
89102
.Build();
90103

91-
private string? GetButtonItemClassString(SelectedItem item) => CssBuilder.Default("btn")
92-
.AddClass($"active bg-{Color.ToDescriptionString()}", CurrentValueAsString == item.Value)
104+
private string? GetButtonItemClassString(SelectedItem<TValue> item) => CssBuilder.Default("btn")
105+
.AddClass($"active bg-{Color.ToDescriptionString()}", Equals(Value, item.Value))
93106
.Build();
94107

95108
/// <summary>
@@ -109,13 +122,14 @@ protected override void OnParametersSet()
109122
/// <summary>
110123
/// 点击选择框方法
111124
/// </summary>
112-
private async Task OnClick(SelectedItem<TValue> item)
125+
private async Task OnClick(SelectedItem<TValue?> item)
113126
{
114127
if (!IsDisabled)
115128
{
129+
CurrentValue = item.Value;
116130
if (OnSelectedChanged != null)
117131
{
118-
await OnSelectedChanged(Items, Value);
132+
await OnSelectedChanged(Value);
119133
}
120134
StateHasChanged();
121135
}

0 commit comments

Comments
 (0)