TextInput
InputSingle-line text input field.
@using Spectre.Console
@using RazorConsole.Components
<Rows>
<TextInput Label="First Name" Value="@_firstName" ValueChanged="OnFirstNameChangedAsync" Placeholder="Ada"
FocusedBorderColor="@Color.DeepSkyBlue1" BorderPadding="@_inputPadding" Expand="true" />
<TextInput Label="Secret Note" Value="@_secretNote" ValueChanged="OnSecretChangedAsync" Placeholder="Classified"
MaskInput="true" FocusedBorderColor="@Color.DeepSkyBlue1" BorderPadding="@_inputPadding" Expand="true" />
<Markup Content="@PreviewText" />
<Markup Content="@SecretLengthText" Foreground="@Color.Grey70" Decoration="@Decoration.Italic" />
</Rows>
@code {
private static readonly Padding _inputPadding = new(1, 0, 1, 0);
private string _firstName = string.Empty;
private string _secretNote = string.Empty;
private string PreviewText => _firstName.Length == 0
? "Preview: (none)"
: $"Preview: {_firstName}";
private string SecretLengthText => $"Stored secret length: {_secretNote.Length}";
private Task OnFirstNameChangedAsync(string? value)
{
_firstName = value ?? string.Empty;
StateHasChanged();
return Task.CompletedTask;
}
private Task OnSecretChangedAsync(string? value)
{
_secretNote = value ?? string.Empty;
StateHasChanged();
return Task.CompletedTask;
}
}Parameters
25| Name | Type | Default | Description |
|---|---|---|---|
Behavior | |||
Disabled | Boolean | — | Whether the input is disabled. When disabled, cannot receive focus or accept input. |
FocusOrder | Nullable<Int32> | — | Tab order for keyboard navigation. Lower values receive focus first. If null , natural document order is used. |
Appearance | |||
BorderColor | Color | — | Border color when input is not focused and not disabled. |
BorderPadding | Padding | — | Padding between the border and the content. |
BorderStyle | BoxBorder | — | Style of the input border. |
DisabledBorderColor | Color | — | Border color when input is disabled. |
FocusedBorderColor | Color | — | Border color when input has focus. |
LabelColor | Color | — | Color of the label text. |
LabelDecoration | Decoration | — | Decoration style of the label text. |
PlaceholderColor | Color | — | Color of the placeholder text. |
PlaceholderDecoration | Decoration | — | Decoration style of the placeholder text. |
ValueColor | Color | — | Color of the input value text. |
Events | |||
OnBlur | EventCallback<FocusEventArgs> | — | Event callback invoked when input loses focus. |
OnFocus | EventCallback<FocusEventArgs> | — | Event callback invoked when input receives focus. |
OnInput | EventCallback<String> | — | Event callback invoked on each character input (fired for every keystroke). |
OnSubmit | EventCallback<String> | — | Event callback invoked when submitting input (typically by pressing Enter). |
ValueChanged | EventCallback<string> | — | Event callback invoked when the value changes. |
Common | |||
ContentPadding | Padding | — | Padding around the input content. |
Label | String | — | Label text displayed above the input field. If null or empty, no label is shown. |
Value | string | — | Current value of the text input. Supports two-way binding with @bind-Value. |
ValueExpression | System.Linq.Expressions.Expression<System.Func{System.String>} | — | Expression identifying the bound value for validation scenarios with EditContext. |
Other | |||
AdditionalAttributes | IReadOnlyDictionary<String, Object> | — | Additional HTML attributes to apply to the input element. |
Expand | Boolean | — | Whether the input should expand to fill available horizontal space. |
MaskInput | Boolean | — | Whether input characters should be masked (displayed as bullets). Useful for password fields. Default is false . |
Placeholder | string? | — | Placeholder text shown when input is empty. |