Blazor TextAreaInput
The Blazor Bootstrap TextAreaInput component provides a multi-line plain-text editing control, ideal for scenarios requiring users to input substantial amounts of free-form text. Common use cases include comment sections on reviews or review descriptions, or feedback forms.
Basic usage #
Text alignment #
You can change the text alignment according to your need. Use the
TextAlignment
parameter to set the alignment. In the below example, alignment is set to center and end.Disable #
Use the
Disabled
parameter to disable the TextAreaInput
.Entered text:
<div class="mb-3">
<TextAreaInput @bind-Value="@enteredText" Rows="3" Disabled="@disabled" Placeholder="Enter text" />
</div>
<div class="mb-3">Entered text: @enteredText</div>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" @onclick="Toggle"> Toggle </Button>
@code {
private string? enteredText = null;
private bool disabled = true;
private void Enable() => disabled = false;
private void Disable() => disabled = true;
private void Toggle() => disabled = !disabled;
}
Also, use Enable() and Disable() methods to enable and disable the
TextAreaInput
.NOTE
Do not use both the Disabled parameter and Enable() & Disable() methods.
Entered text:
<div class="mb-3">
<TextAreaInput @ref="textAreaInputRef" @bind-Value="@enteredText" Rows="3" Placeholder="Enter text" />
</div>
<div class="mb-3">Entered text: @enteredText</div>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
@code {
private TextAreaInput? textAreaInputRef;
private string? enteredText = null;
private void Disable() => textAreaInputRef.Disable();
private void Enable() => textAreaInputRef.Enable();
}
Max length #
Use the
MaxLength
parameter to set the maximum length of the TextAreaInput
.Valdations #
Like any other blazor input component,
TextAreaInput
supports validations.
Add the DataAnnotations on the TextAreaInput
component to validate the user input before submitting the form.
In the below example, we used Required attribute.
Events: ValueChanged #
This event fires when the
TextAreaInput
value changes, but not on every keystroke.