Skip to content

[dev-v5] feat: add easier way to display null in FluentSelect #4194

@MarvinKlein1508

Description

@MarvinKlein1508

🙋 Feature Request

v5 allows you to create a nullable FluentSelect like this:

@using Samples = SampleData.People;

<FluentSelect Label="Coworker"
              Placeholder="Select a coworker"
              Items="@Coworkers"
              @bind-Value="@Value"
              OptionText="@(item => item?.FirstName)"
              OptionValue="@(item => item?.Id)"
              OptionDisabled="@(item => item == Coworkers.ElementAt(3))" />

<div>
    Selected: @Value?.Id - @Value?.FirstName
</div>

@code {
    static Samples.Person?[] OneNullPerson = new Samples.Person?[] { null };
    static Samples.Person?[] Coworkers =>
          OneNullPerson.Union(Samples.Persons.Take(5).ToArray()).ToArray();

    Samples.Person? Value = Coworkers.ElementAt(2);
}

This requires some additional effort from the developer everytime. It would be great if this can be handled by the library somehow.

💁 Possible Solution

Perhaps we can introduce a new parameter AllowNull which will automatically append it as the first option. The OptionText can then handle the null-case to display a message. We could even add another property NullTemplate which can be defined by the user with the new defaults feature.

🔦 Context

I have a like 20 selects in one form which are all nullable. This would reduce the amount of work for the developer a lot and would make this component even more useful IMO.

Metadata

Metadata

Assignees

Labels

status:needs-investigationNeeds additional investigationv5For the next major version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions