TextEdit component

<TextEdit> fields components are used for collecting user provided information.

Examples

Basic

<TextEdit />

Placeholder

<TextEdit Placeholder="Some text value..." />

Static text

Static text removes the background, border, shadow, and horizontal padding, while maintaining the vertical spacing so you can easily align the input in any context, like a horizontal form.
<TextEdit Plaintext />

Disabled

A disabled input element is unusable and un-clickable.
<TextEdit Disabled />

ReadOnly

If you use the read-only attribute, the input text will look similar to a normal one, but is not editable.
<TextEdit ReadOnly />

Sizing

Sets the heights of input elements.
<TextEdit Size="Size.Small" />
<TextEdit Size="Size.Large" />

Pattern

Use pattern attribute to specify regular expression that will be used while validating the input text value.
Pattern does not match!
<Validation UsePattern="true">
    <TextEdit Pattern="[A-Za-z]{3}">
        <Feedback>
            <ValidationError>Pattern does not match!</ValidationError>
        </Feedback>
    </TextEdit>
</Validation>

EditMask

Edit masks are used to prevent user from entering an invalid values and when entered string must match a specific format. For example you can limit input to only accept numeric string, date string or if you want full control you can use RegEx format.
<TextEdit MaskType="MaskType.RegEx" EditMask="^[a-zA-Z ]*$" />

Roles

Use Role to define type of text value.
<TextEdit Role="TextRole.Email" />
<TextEdit Role="TextRole.Password" />

Binding

Two-way binding

By using bind-* attribute the text will be automatically assigned to the member variable.
<TextEdit @bind-Text="@name" />
@code{
    string name;
}

Manual event binding

When using the event TextChanged, you also must define the Text value attribute.
<TextEdit Text="@name" TextChanged="@OnNameChanged" />
@code{
    string name;

    Task OnNameChanged( string value )
    {
        name = value;

        return Task.CompletedTask;
    }
}

Settings

Text Changed mode

By default the TextChanged event will be raised on every keypress. To override default behavior of TextChanged event and to disable the change on every keypress you must set the ChangeTextOnKeyPress to false on application start. After setting it to false the event will be raised only after the input loses focus.
public void ConfigureServices( IServiceCollection services )
{
  services
    .AddBlazorise( options =>
    {
      options.ChangeTextOnKeyPress = false;
    } );
}

Text Delay mode

Because of some limitations in Blazor, sometimes there can be problems when ChangeTextOnKeyPress is enabled. Basically if you try to type too fast into the text field the caret can jump randomly from current selection to the end of the text. To prevent that behaviour you need to enable DelayTextOnKeyPress. Once enabled it will slightly delay every value entered into the field to allow the Blazor engine to do it’s thing. By default this option is disabled.
public void ConfigureServices( IServiceCollection services )
{
  services
    .AddBlazorise( options =>
    {
      options.DelayTextOnKeyPress = true;
      options.DelayTextOnKeyPressInterval = 300;
    } );
}

Attributes

Name Description Type Default
Role The role of the input text. TextRole Text
Text Input value. string null
TextChanged Occurs after text has changed. EventCallback<string>
Plaintext Remove the default form field styling and preserve the correct margin and padding. bool false
ReadOnly Prevents modification of the input’s value. bool false
Disabled Prevents user interactions and make it appear lighter. bool false
MaxLength Specifies the maximum number of characters allowed in the input element. int? null
Placeholder Sets the placeholder for the empty text. string null
Pattern Specifies a regular expression that the input element’s value is checked against on form validation. string null
Color Component visual or contextual style variants. Color None
Size Component size variations. Size None
EditMask A string representing a edit mask expression.
MaskType Specify the mask type used by the editor. MaskType None
VisibleCharacters Specifies the visible width, in characters, of an <input> element. int? null
ChangeTextOnKeyPress If true the text in will be changed after each key press (overrides global settings). bool? null
DelayTextOnKeyPress If true the entered text will be slightly delayed before submitting it to the internal value. bool? null
DelayTextOnKeyPressInterval Interval in milliseconds that entered text will be delayed from submitting to the internal value. bool? null
KeyDown Occurs when a key is pressed down while the control has focus. EventCallback<KeyboardEventArgs>
KeyDown Occurs when a key is pressed down while the control has focus. EventCallback<KeyboardEventArgs>
KeyPress Occurs when a key is pressed while the control has focus. EventCallback<KeyboardEventArgs>
KeyUp Occurs when a key is released while the control has focus. EventCallback<KeyboardEventArgs>
OnFocus Occurs when the input box gains focus. EventCallback<KeyboardEventArgs>
FocusIn Occurs when the input box gains focus. EventCallback<KeyboardEventArgs>
FocusOut Occurs when the input box loses focus. EventCallback<KeyboardEventArgs>
Autofocus Set’s the focus to the component after the rendering is done. bool false