I have component with a textarea inside where user can set the rows via parameter. Now i want to make this textarea to grow as user types. The entered parameter becomes minimum number of rows.
What i have now:
Component.razor
<textarea rows="@Rows"
value="@Value"
@oninput=@ChangeValueAsync />
Component.razor.cs
private int MinRows { get; set; } = 1;
[Parameter]
public int Rows{ get; set; }
[Parameter]
public string Value { get; set; } = string.Empty;
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
private async Task ChangeValueAsync(ChangeEventArgs args)
{
Rows= Math.Max(MinRows, Math.Max(Value.Split('\n').Length, Value.Split('\r').Length)+1);
await ValueChanged.InvokeAsync(args?.Value?.ToString());
}
protected override void OnParametersSet()
{
MinRows = Math.Abs(Math.Max(1,Rows));
base.OnParametersSet();
}
In debugger i can read the Rows number is calculated correctly, but textarea doesn't resize. Can anyone explain it to me why is the textarea still the same?
Oh.. The important thing is not to use JavaScript.