-
Notifications
You must be signed in to change notification settings - Fork 461
[dev-v5] Add a generic FluentOption<TOption> #4456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
✅ All tests passed successfully Details on your Workflow / Core Tests page. |
Summary - Unit Tests Code CoverageSummary
CoverageMicrosoft.FluentUI.AspNetCore.Components - 98.8%
|
|
@dvoituron the current code works with non nullable properties. However selection via code does not work properly yet. Add <FluentButton OnClick="() => SelectedLanguageId = 1">Select C#</FluentButton>to the sample and then hit it. The value changes but not the displayed one on the dropdown. Using null as option breaks the component. See this code for reference: <FluentSelect Label="Language" @bind-Value="@SelectedLanguageId">
<FluentOption TOption="int?" Value="null"></FluentOption>
@foreach (var language in Languages)
{
<FluentOption Value="@language.Id">
@language.Name
</FluentOption>
}
</FluentSelect>
<div>
Selected: @(SelectedLanguageId?.ToString() ?? "<NULL>")
</div>
@code {
int? SelectedLanguageId;
static Language[] Languages = new Language[]
{
new(1, "C#"),
new(2, "Java"),
new(3, "Python"),
new(4, "JavaScript"),
new(5, "Go")
};
record Language(int Id, string Name);
} |
The |
When I want to provide a manual item then I have to. <FluentOption TOption="int?" Value="null"></FluentOption>This item should mimic the default state and allows the user to unselect a previous selected option. |
MarvinKlein1508
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing and it works pretty well so far. I would update the language sample to having a null value as well.
For example:
<!-- Using Items -->
<FluentSelect Label="Language"
Items="@Languages"
@bind-Value="@SelectedId1"
OptionText="@(i => i.Name)"
OptionBindedValue="@(i => i.Id)" />
<!-- Using FluentOptions -->
<FluentSelect Label="Language"
TOption="Language"
TValue="int?"
@bind-Value="@SelectedId2">
<FluentOption TValue="int?" Value="null">--- Select ---</FluentOption>
@foreach (var language in Languages)
{
<FluentOption TValue="int?" Value="@language.Id">
@language.Name
</FluentOption>
}
</FluentSelect>
<div>
IDs: (@SelectedId1, @SelectedId2)
</div>
@code {
int SelectedId1 = 3;
int? SelectedId2 = 3;
static Language[] Languages = new Language[]
{
new(1, "C#"),
new(2, "Java"),
new(3, "Python"),
new(4, "JavaScript"),
new(5, "Go")
};
record Language(int Id, string Name);
}In vanilla Blazor this part is representing <option value=""></option> for setting back to null for any nullable type.
Also I have noticed that setting the selected items via code is not working as expected.
Try adding this 3 buttons to the language demo
<FluentButton OnClick="() => SelectedId1 = 1">Set first to C#</FluentButton>
<FluentButton OnClick="() => SelectedId2 = 1">Set second to C#</FluentButton>
<FluentButton OnClick="() => SelectedId2 = null">Set second to null</FluentButton>|
btw. these changes also fix #4295 for me |
…-v5/fluent-option-typed
…and OptionValue to OptionValueToString (formats value for HTML)
|
@dvoituron there is still an issue when setting the second language example via code. <FluentButton OnClick="() => SelectedId1 = 1">Set first to C#</FluentButton>
<FluentButton OnClick="() => SelectedId2 = 1">Set second to C#</FluentButton>
<FluentButton OnClick="() => SelectedId2 = null">Set second to null</FluentButton>First button works fine. The other two are changing the value but the dropdown will still display the wrong one. |
No. This is a Blazor behavior: you need to add ’@key’ to fix that. I added this info in the markdown page (below the example) |


[dev-v5] Add a generic FluentOption
This pull request introduces a generic
FluentOption<TOption>component, enabling type-safe options for FluentSelect, FluentCombobox, and related components, and updates supporting infrastructure and samples accordingly.Example:
Unit Tests
100%: Updated