thomasagarza
thomasagarza

Reputation: 123

Set Rows Attribute for Blazor (Server) InputTextArea

I am building a Blazor (Server) EditForm which contains an InputTextArea. By default, it looks like the InputTextArea creates a textArea with 2 rows, but I would prefer 4 rows for this specific application.

How do you set the number of rows for a Blazor InputTextArea?

Upvotes: 8

Views: 9774

Answers (2)

Umair
Umair

Reputation: 5501

You can simply add the rows attribute like below.

<InputTextArea @bind-Value="@prop" rows="4"></InputTextArea>

It does not require any C# as this is just html.

Upvotes: 19

thomasagarza
thomasagarza

Reputation: 123

I would love to know if there is another way, but after searching for a while, I was able to find this solutions.

  1. In your C# code, create a property of type Dictionary<string, object>.

     Dictionary<string, object> inputTextAreaAttributes = new Dictionary<string, object>();
    
  2. Override OnInitializedAsync and add a new item to your dictionary.

     Dictionary<string, object> inputTextAreaAttributes = new Dictionary<string, object>();
    
     protected override Task OnInitializedAsync()
     {
         inputTextAreaAttributes.Add("rows", "4");
     }
    
  3. Set the @Attribute property of the InputTextArea to your dictionary.

     <InputTextArea @bind-Value="@prop" @attributes="inputTextAreaAttributes"></InputTextArea>
    

Upvotes: 3

Related Questions