dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.59k stars 9.79k forks source link

ability to override `CssClass` property in `InputBase<T>` #55684

Closed ParsaGachkar closed 2 weeks ago

ParsaGachkar commented 2 weeks ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I want to be able to override the CssClass field in my custom Input that inherits from InputBase<T> and set a custom value to it!

Describe the solution you'd like

please make CssClass property of InputBase<T> virtual

Additional context

No response

mkArtakMSFT commented 2 weeks ago

Thanks for contacting us. Because you're interested in overriding the InputBase<T> you can already decide what to actually render in the overridden BuildRenderTree method, where you can choose to render some other property, your custom implementation provides instead of CssClass. Will that not cover your needs here?

ParsaGachkar commented 2 weeks ago

Thanks for contacting us. Because you're interested in overriding the InputBase<T> you can already decide what to actually render in the overridden BuildRenderTree method, where you can choose to render some other property, your custom implementation provides instead of CssClass. Will that not cover your needs here?

The problem is that I'll end up with a duplicate code while setting up the wiring of my input, which is already available at InputText. For instance, I just want to prepend a specific css class for my text input! A simple override from text input and overriding its css property would really simplify the task.

MariovanZeist commented 2 weeks ago

@ParsaGachkar You can add any CSS class to an InputBase<T> descendant without overriding the code. Add the class attribute like

  <InputText class="my-class" @bind-Value=value />

Now my-class will be added to the value of CssClass and set on the HTML

InputBase

mkArtakMSFT commented 2 weeks ago

Thanks for contacting us. While this may be a great idea, it is not aligned with our long-term vision to make it part of the framework. For many other ideas which don't belong to the framework we encourage the community to build and ship on their own, contributing to the expanding .NET Ecosystem.

You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.