Reputation: 123
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
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
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.
In your C# code, create a property of type Dictionary<string, object>.
Dictionary<string, object> inputTextAreaAttributes = new Dictionary<string, object>();
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");
}
Set the @Attribute property of the InputTextArea to your dictionary.
<InputTextArea @bind-Value="@prop" @attributes="inputTextAreaAttributes"></InputTextArea>
Upvotes: 3