What features should a component have? Too many and it isn’t as reusable. Too few and it doesn’t provide much benefit. Examining the components that come with Blazor might help to answer this question. Let’s start with the InputText component which can only be used inside the EditForm. This Razor markup
provides a green outline after the value is changed.
Adding a DataAnnotation like [Required] to the models property
and the DataAnnotationsValidator inside the EditForm
provides a red outline when validation fails.
Adding the ValidationMessage component below the InputText component
produces a validation error message below the input.
In my opinion these are pretty useful features that I’d use a lot. I’d also typically use a label
above the input.
Lines 28 through 32 provide a set of features I believe would get a lot of reuse and therefore seem like a good set of features for a component. However there are two more abilities I’d like to include in this component. The ability to use it outside of an EditForm and the ability to display server validation errors like an email address already exists. I’ll put together a component with these features in the next post. Thanks for reading.