Skip to content

Commit d23c876

Browse files
authored
feat(Select): compatible enum value as Items (#5434)
* refactor: 精简代码 * feat: 兼容 Enum Value 数字情况 * chore: bump version 9.3.1-beta33
1 parent 1e1ed9a commit d23c876

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.3.1-beta32</Version>
4+
<Version>9.3.1-beta33</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Select/Select.razor.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ private SelectedItem? SelectedRow
294294

295295
private SelectedItem? GetSelectedRow()
296296
{
297-
var item = Rows.Find(i => i.Value == CurrentValueAsString)
297+
var item = GetItemWidthEnumValue()
298+
?? Rows.Find(i => i.Value == CurrentValueAsString)
298299
?? Rows.Find(i => i.Active)
299300
?? Rows.FirstOrDefault(i => !i.IsDisabled)
300301
?? GetVirtualizeItem(CurrentValueAsString);
@@ -314,6 +315,10 @@ private SelectedItem? SelectedRow
314315
return item;
315316
}
316317

318+
private SelectedItem? GetItemWidthEnumValue() => ValueType.IsEnum
319+
? Rows.Find(i => i.Value == Convert.ToInt32(Value).ToString())
320+
: null;
321+
317322
private List<SelectedItem> GetRowsByItems()
318323
{
319324
var items = new List<SelectedItem>();
@@ -328,7 +333,7 @@ private List<SelectedItem> GetRowsByItems()
328333
private List<SelectedItem> GetRowsBySearch()
329334
{
330335
var items = OnSearchTextChanged?.Invoke(SearchText) ?? FilterBySearchText(GetRowsByItems());
331-
return items.ToList();
336+
return [.. items];
332337
}
333338

334339
private IEnumerable<SelectedItem> FilterBySearchText(IEnumerable<SelectedItem> source) => string.IsNullOrEmpty(SearchText)

src/BootstrapBlazor/Extensions/ObjectExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ public static bool TryConvertTo<TValue>(this string? source, [MaybeNullWhen(fals
185185
}
186186
else if (source == string.Empty)
187187
{
188-
ret = BindConverter.TryConvertTo<TValue>(source, CultureInfo.CurrentCulture, out val);
188+
ret = BindConverter.TryConvertTo(source, CultureInfo.CurrentCulture, out val);
189189
}
190190
else
191191
{
192192
var isBoolean = type == typeof(bool);
193193
var v = isBoolean ? (object)source.Equals("true", StringComparison.CurrentCultureIgnoreCase) : source;
194-
ret = BindConverter.TryConvertTo<TValue>(v, CultureInfo.CurrentCulture, out val);
194+
ret = BindConverter.TryConvertTo(v, CultureInfo.CurrentCulture, out val);
195195
}
196196
}
197197
catch

0 commit comments

Comments
 (0)