-
Notifications
You must be signed in to change notification settings - Fork 10.7k
InputSelectEnum #34823
Copy link
Copy link
Closed as not planned
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsdesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionThis issue represents a design proposal for a different issue, linked in the descriptionenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureFeatures related to the built in components we ship or could ship in the future
Milestone
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsdesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionThis issue represents a design proposal for a different issue, linked in the descriptionenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the futureFeatures related to the built in components we ship or could ship in the future
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
A new Blazor form component that automatically lists enum values that an InputSelect can receive.
Motivation and goals
I often find myself writing this same
InputSelectcode over and over:A separate
InputSelectEnum<TValue>component that removes this boilerplate could be useful, imo.I would write this privately for myself, copying the existing InputSelect code and tweaking it. The only changes from the existing code is a modification of the BuildRenderTree method to generate options instead of displaying child content.
However, certain pieces of the
InputSelectcode that I'd use as a baseline areinternal, such as the InputExtensions.TryParseSelectableValueFromString method and InputBase.FieldIdentifier used for value binding and validation messages, respectively.In scope
selectwith all possible enum valuesTValueFunc<TValue, string>. When this parameter is absent, display usingSystem.CompnentModel.DataAnnotations.DisplayAttribute.Nameif available, thenToString()Out of scope
Risks / unknowns
If we wish to support nullable enums, then using the generic constraint
where TValue : Enumis not a valid path. Therefore, type validity will need to be enforced at runtime.Examples
An existing example of another developer implementing this component can be found here. That particular implementation may have been using the value binding code from this repo as it existed but it now differs from the code we find in main, and thus results in an inconsistent experience alongside the equivalent InputSelect.