-
-
Notifications
You must be signed in to change notification settings - Fork 364
Closed
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
In following demo, the value of RadioList is set to ChartType.Line.
.razor:
@{
var types = new List<SelectedItem<ChartType>>
{
new() { Value = ChartType.Bar, Text = "柱状图" },
new() { Value = ChartType.Pie, Text = "饼图" },
};
}
<RadioList TValue="ChartType" Items="types" IsButton="true" @bind-Value="@ChartType"></RadioList>.razor.cs:
private ChartType ChartType { get; set; } = ChartType.Bar;Cause
When checking current and default value, it is checking whether SelectedItem.Value which is of type string rather than generic type TValue, resulting in inequality (L73) and null return value of FirstOrDefault() (L75).

ref:
| if (AutoSelectFirstWhenValueIsNull && !Items.Any(i => i.Value == CurrentValueAsString)) | |
| { | |
| CurrentValueAsString = Items.FirstOrDefault()?.Value ?? ""; | |
| } |
Expected Behavior
if expression in L73 is false.
Even when it is true (current value has not been set), L75 should return ChartType.Bar, which is the first value of the given list.
Interactive render mode
Interactive Server (Interactive server-side rendering (interactive SSR) using Blazor Server)
Steps To Reproduce
Use List<SelectedItem<ChartType>> as source of RadioList.
.razor:
@{
var types = new List<SelectedItem<ChartType>>
{
new() { Value = ChartType.Bar, Text = "柱状图" },
new() { Value = ChartType.Pie, Text = "饼图" },
};
}
<RadioList TValue="ChartType" Items="types" IsButton="true" @bind-Value="@ChartType"></RadioList>.razor.cs:
private ChartType ChartType { get; set; } = ChartType.Bar;Exceptions (if any)
No response
.NET Version
8
Anything else?
No response
ArgoZhang
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working