Skip to main content

LgTextBox

LgTextBox is the text input field: single line, multiline area, password, with optional input mask. The value (a string) binds with @bind-Value.

<LgTextBox Label="#ContactName" @bind-Value="_model.Name" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgInputRenderBase<string> → LgInputBase<string> → LgAriaComponentBase → LgComponentBase
  • NuGet package: Lagoon.UI
Specialized variants

LgTextBox serves as the base for several ready-to-use fields: LgSuggestBox (suggestions during input) and LgColorPickerBox (color picker).

Usage​

Demo​

Try this component in the Lagoon showcase.

Simple input​

Placeholder displays hint text, Disabled disables the field, and ReadOnly displays it read-only.

ContactPage.razor
<LgTextBox Label="#ContactName" @bind-Value="_model.Name" />

<LgTextBox Label="#FirstName"
Placeholder="#TypeYourFirstName"
Disabled="_isDisabled"
ReadOnly="_isReadOnly"
@bind-Value="_model.FirstName" />
ContactPage.razor.cs
public partial class ContactPage : LgPage
{
// Screen-driven states: disable and read-only the second field.
private bool _isDisabled;
private bool _isReadOnly;

private readonly ContactVm _model = new();

private sealed class ContactVm
{
public string Name { get; set; }
public string FirstName { get; set; }
}
}

Password​

TextMode="TextBoxMode.Password" masks entered characters.

AccountPage.razor
<LgTextBox Label="#Password"
TextMode="TextBoxMode.Password"
@bind-Value="_model.Password" />
AccountPage.razor.cs
public partial class AccountPage : LgPage
{
private readonly AccountVm _model = new();

private sealed class AccountVm
{
public string Password { get; set; }
}
}

Multiline area​

TextMode="TextBoxMode.Multiline" renders a text area. Rows sets the number of lines, MinRows / MaxRows limit automatic adjustment, and AllowResize allows manual resizing.

CommentPage.razor
<LgTextBox Label="#Comment"
TextMode="TextBoxMode.Multiline"
Rows="5"
MaxLength="500"
AllowResize="true"
@bind-Value="_model.Comment" />
CommentPage.razor.cs
public partial class CommentPage : LgPage
{
private readonly CommentVm _model = new();

private sealed class CommentVm
{
public string Comment { get; set; }
}
}

Input mask​

InputMaskKind chooses the mask type and InputMask the pattern (9: digit, a: letter, *: alphanumeric for the Mask type). InputMaskPlaceholder sets the character that fills still empty positions of the mask (# with the mask 99-99-99-99-99 displays ##-##-##-##-##); without a value, the default character _ is preserved. It must not be confused with Placeholder, which remains the hint text displayed when the field is empty. AutoUnmask returns the value without the mask and ClearIncomplete clears the input if the mask is incomplete.

note

The input mask applies only to plain text mode. It is ignored without error when TextMode equals TextBoxMode.Multiline or TextBoxMode.Password: the mask library targets single-line fields, and a filler character would make no sense on password characters already masked.

PhonePage.razor
<LgTextBox Label="#Phone"
InputMaskKind="InputMaskKind.Mask"
InputMask="99 99 99 99 99"
InputMaskPlaceholder="#"
Placeholder="#PhoneHint"
AutoUnmask="true"
@bind-Value="_model.Phone" />

@* Built-in email input mask. *@
<LgTextBox Label="#Email"
InputMaskKind="InputMaskKind.Email"
@bind-Value="_model.Email" />
PhonePage.razor.cs
public partial class PhonePage : LgPage
{
private readonly PhoneVm _model = new();

private sealed class PhoneVm
{
public string Phone { get; set; }
public string Email { get; set; }
}
}

Prefix, suffix, and datalist​

Prefix / Suffix display text or an icon in the field. DataList renders an HTML datalist suggesting values during input.

ReferencePage.razor
<LgTextBox Label="#Reference"
Prefix="REF-"
PrefixType="InputLabelType.Text"
DataList="_knownReferences"
@bind-Value="_model.Reference" />
ReferencePage.razor.cs
public partial class ReferencePage : LgPage
{
// Values suggested by the browser during input (HTML datalist).
private readonly List<string> _knownReferences = new() { "1001", "1002", "2001" };

private readonly ReferenceVm _model = new();

private sealed class ReferenceVm
{
public string Reference { get; set; }
}
}

Responding to value changes​

OnChangingAsync is called before assignment and allows canceling the change (args.Cancel); OnChange is called after. OnInput notifies each keystroke and OnKeyUp each key released. Clearing by the clear button also triggers OnInput, with an empty value (""), like the browser for a search field cleared by its cross button: a filter field that only listens to OnInput therefore does not need to wire OnReset to the same handler. It does not trigger if it is canceled (OnChangingAsync, ConfirmationMessage).

CodePage.razor
<LgTextBox Label="#ProjectCode"
OnChangingAsync="OnCodeChangingAsync"
@bind-Value="_model.Code" />
CodePage.razor.cs
public partial class CodePage : LgPage
{
private readonly CodeVm _model = new();

// Called before change: refuses reserved codes.
private Task OnCodeChangingAsync(ChangingEventArgs<string> args)
{
if (args.NewValue == "ADMIN")
{
args.Cancel = true;
ShowWarning("#ReservedCode");
}
return Task.CompletedTask;
}

private sealed class CodeVm
{
public string Code { get; set; }
}
}

Properties​

All [Parameter] properties of the component, including inherited ones.

NameTypeDefaultDeclared inDescription
AllowResizeboolfalseLgTextBoxAllows resizing when TextMode equals TextBoxMode.Multiline.
AutoCompleteboolfalseLgTextBoxEnables browser autocomplete if true; otherwise the attribute autocomplete="off" is rendered.
AutoUnmaskboolfalseLgTextBoxReturns the value without the mask when InputMask is used.
ClearIncompleteboolfalseLgTextBoxClears the value if the input mask is incomplete.
DataListList<string>nullLgTextBoxList of values used to render a datalist associated with the input.
InputMaskstringnullLgTextBoxInput mask applied to the text field.
InputMaskKindInputMaskKindNoneLgTextBoxType of input mask.
InputMaskPlaceholderstringnullLgTextBoxCharacter filling empty positions of the input mask (for example # with the mask 99-99-99-99-99 displays ##-##-##-##-##). Must not be confused with Placeholder. Without a value, the default mask character (_) is preserved. Ignored when InputMaskKind equals Regex.
MaxLengthint?nullLgTextBoxMaximum number of characters. If not defined, it is inferred from the MaxLength attribute of the model.
MaxRowsint?nullLgTextBoxMaximum number of lines when TextMode equals TextBoxMode.Multiline.
MinRowsint?nullLgTextBoxMinimum number of lines when TextMode equals TextBoxMode.Multiline.
OnChangeDisabledboolfalseLgTextBoxDisables the native onchange handler of the field.
OnChangingAsyncFunc<ChangingEventArgs<string>, Task>nullLgTextBoxCallback called before value change; the change can be canceled there.
OnFocusEventCallback<FocusEventArgs>—LgTextBoxCallback called when the field receives focus.
OnInputEventCallback<ChangeEventArgs>—LgTextBoxCallback called on input (oninput) and when reset by the clear button (value "").
OnKeyUpEventCallback<KeyboardEventArgs>—LgTextBoxCallback called when a key is released.
PlaceholderstringnullLgTextBoxHint text displayed when the field is empty. Distinct from InputMaskPlaceholder.
Rowsint?nullLgTextBoxNumber of lines when TextMode equals TextBoxMode.Multiline.
TextModeTextBoxMode?nullLgTextBoxMode of the text field. null renders a simple text field.
PrefixstringnullLgInputRenderBasePrefix displayed in the field.
PrefixTypeInputLabelTypeTextLgInputRenderBaseNature of the prefix.
SuffixstringnullLgInputRenderBaseSuffix displayed in the field.
SuffixTypeInputLabelTypeTextLgInputRenderBaseNature of the suffix.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgInputBaseAdditional HTML attributes applied to the rendered element.
AutoFocusboolfalseLgInputBaseGives focus to the field on first render.
ConfirmationMessagestringnullLgInputBaseConfirmation message displayed before applying a value change.
ContainerIInputContainer<string>nullLgInputBaseInternal use: attaches a GridView cell to the field.
CssClassstringnullLgInputBaseAdditional CSS classes.
DisabledboolfalseLgInputBaseDisables the field.
DisplayNamestringnullLgInputBaseName of the field used in error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message below the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content of the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after value change.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to edit the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays the field read-only.
Requiredbool?nullLgInputBaseRequired field. If null, inferred from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseDisplays the clear button. If null, the application's behavior configuration applies.
ResetTextstringnullLgInputBaseText of the clear button.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) of the clear button.
TooltipstringnullLgInputBaseTooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates whether the content of the Tooltip is in HTML format (otherwise plain text).
ValuestringnullLgInputBaseBound value (@bind-Value).
ValueChangedEventCallback<string>—LgInputBaseCallback for updating the bound value.
ValueExpressionExpression<Func<string>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

LgTextBox also consumes parameters automatically provided by ancestor components (you do not need to define them): ParentAuthorizeView (LgAuthorizeView) and the editing context of a parent LgEditForm.

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<string>, Task>Before value change; args.Cancel = true cancels the change.
OnChangeEventCallback<ChangeEventArgs>After value change.
OnInputEventCallback<ChangeEventArgs>On each field content modification, including reset by the clear button (value "", unless the reset is canceled).
OnKeyUpEventCallback<KeyboardEventArgs>When a key is released in the field.
OnFocusEventCallback<FocusEventArgs>When the field receives focus.
OnResetEventCallback<ChangeEventArgs>When reset by the clear button.

Associated enumerations​

TextBoxMode​

Rendering mode of the field (property TextMode; null renders a simple text field).

ValueDescription
MultilineRenders a multiline text area.
PasswordRenders a password field.

InputMaskKind​

Type of input mask (property InputMaskKind).

ValueDescription
NoneNo mask (default value).
MaskMask based on 9 (digit), a (letter), and * (alphanumeric).
RegexRegex-based mask.
EmailEmail input mask.

Best practices / accessibility​

  • Provide Label (or AriaLabel): the label carries the field's accessibility and the required field indicator.
  • MaxLength is inferred from the MaxLength attribute of the model: set the constraint on the view model rather than hardcoded in the markup.
  • For long text edited in a modal, prefer LgSummaryBox.
Complete reference

All parameters (including inherited ones): API reference — LgTextBox.