TextInput

Input

Single-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
NameTypeDefaultDescription
Behavior
DisabledBooleanWhether the input is disabled. When disabled, cannot receive focus or accept input.
FocusOrderNullable<Int32>Tab order for keyboard navigation. Lower values receive focus first. If null , natural document order is used.
Appearance
BorderColorColorBorder color when input is not focused and not disabled.
BorderPaddingPaddingPadding between the border and the content.
BorderStyleBoxBorderStyle of the input border.
DisabledBorderColorColorBorder color when input is disabled.
FocusedBorderColorColorBorder color when input has focus.
LabelColorColorColor of the label text.
LabelDecorationDecorationDecoration style of the label text.
PlaceholderColorColorColor of the placeholder text.
PlaceholderDecorationDecorationDecoration style of the placeholder text.
ValueColorColorColor of the input value text.
Events
OnBlurEventCallback<FocusEventArgs>Event callback invoked when input loses focus.
OnFocusEventCallback<FocusEventArgs>Event callback invoked when input receives focus.
OnInputEventCallback<String>Event callback invoked on each character input (fired for every keystroke).
OnSubmitEventCallback<String>Event callback invoked when submitting input (typically by pressing Enter).
ValueChangedEventCallback<string>Event callback invoked when the value changes.
Common
ContentPaddingPaddingPadding around the input content.
LabelStringLabel text displayed above the input field. If null or empty, no label is shown.
ValuestringCurrent value of the text input. Supports two-way binding with @bind-Value.
ValueExpressionSystem.Linq.Expressions.Expression<System.Func{System.String>}Expression identifying the bound value for validation scenarios with EditContext.
Other
AdditionalAttributesIReadOnlyDictionary<String, Object>Additional HTML attributes to apply to the input element.
ExpandBooleanWhether the input should expand to fill available horizontal space.
MaskInputBooleanWhether input characters should be masked (displayed as bullets). Useful for password fields. Default is false .
Placeholderstring?Placeholder text shown when input is empty.

API