Blazor EnumInput
The Blazor Bootstrap EnumInput component renders a dropdown list from an enumeration (enum), enabling users to select from a predefined set of options. It simplifies data entry by binding directly to enum types and supports customization with sizes.
How it works #
The EnumInput component displays enum values in a dropdown, allowing users to select from a predefined set of options.
Enum labels use
How to use:
This demo shows how to bind both the enum value and text, and how to display the selected result.
DisplayAttribute.GetName() when a DisplayAttribute is present, including resource-backed names, and fall back to the enum member name.
How to use:
- Define an
enumrepresenting your options. - Add the
EnumInputcomponent to your page, specifying theTEnumtype parameter. - Bind the selected value using
@bind-Valueor@bind-Textas needed. - Use the selected value or text in your logic as shown in the demo.
Sizes #
The EnumInput component can be rendered in various sizes to fit different UI requirements.
How to use:
This demo shows how to display EnumInput in different sizes for flexible layout integration.
How to use:
- Set the
Sizeparameter to one of theEnumInputSizevalues (Small,Normal,Large). - Bind the selected value as needed.
Disabled #
The EnumInput component can be disabled to prevent user interaction.
How to use:
This demo demonstrates how to render EnumInput in a disabled state.
How to use:
- Set the
Disabledparameter totrueto make the dropdown non-interactive. - Bind the value as usual; the user will not be able to change it.
Events #
The EnumInput component supports event callbacks for value and text changes, enabling custom logic when the selection changes.
How to use (ValueChanged):
This demo shows how to handle value changes using the ValueChanged event.
How to use (ValueChanged):
- Set the
Valueparameter and handle theValueChangedevent to respond to selection changes. - Update your logic based on the new value in the event handler.
How to use (TextChanged):
This demo shows how to handle text changes using the TextChanged event.
- Set the
Textparameter and handle theTextChangedevent to respond to text changes. - Update your logic based on the new text in the event handler.
Mehods #
The EnumInput component can be enabled or disabled dynamically at runtime.
How to use:
This demo demonstrates how to programmatically enable or disable the EnumInput component.
How to use:
- Bind the
Disabledparameter to a boolean property in your component. - Update the property in your code (e.g., via button click) to enable or disable the EnumInput as needed.