Text inputs

TextBoxControl · NumericTextBoxControl · TextAreaControl · MaskedTextBoxControl · PasswordControl

Collect names, numbers, notes, phone numbers and passwords, bound two ways to your model.

Overview

TextBoxControl is a Blazor text box for a line of text, updated on every keystroke with UpdateOnInput or once users leave the field. Use NumericTextBoxControl for counts and amounts that must stay in range, TextAreaControl for notes with a character limit and spell checking, MaskedTextBoxControl for entries with a fixed format such as a phone number, and PasswordControl for passwords with a reveal button. All five bind with @bind-Value.

Examples

#Traveler details

Type in each field and watch the card: the name on the tag follows every keystroke and has a clear button, the email lands when you leave the box, the traveler count stays between 1 and 12, and Budget refuses anything under $250 a head, with a warning when more travelers leave an accepted budget below that.

ALBUS DOOR Kyoto Classic, 8 nights, 2 travelers Confirmation goes to nobody yet Budget $3,200 ($1,600 a head)

#Notes with a limit

Type up to 200 characters; each button inserts a stock phrase at the caret, and is refused when it would pass the limit. The switch turns on the control's own context menu.

40 / 200 characters

#A phone mask and a password

Set up the lead traveler's portal account: the mobile number is formatted and checked against its Mask when you leave the box, and the password box shows each character for a moment and has an eye to reveal it; the page checks off the rules below it as you type. OnChange reports only numbers the mask accepts, so Create account checks the number again with CommitAsync.

  • 8 characters or more
  • a digit
  • a capital letter

Documentation

ParameterTypeDefaultDescription
Valuestring?nullThe text. Bind with @bind-Value.
ValueExpressionExpression<Func<string?>>?nullSet by @bind-Value. Server-backed edits then notify a surrounding EditForm's EditContext. In the plain case (no UpdateOnInput, OnKeyDown, InputValueChanged, focus or selection options, classic menu, clear button or ClientBuffered) the control renders Blazor's own InputText, or InputTextArea when multi-line.
Placeholderstring?nullHint shown while the box is empty. An explicit placeholder attribute wins.
CssClassstring?nullClass on the input, merged with any class attribute. Without one the input has no styling of its own; this page adds text-field.
Widthstring?nullCSS width written as an inline style, such as 250px or 100%. On a password box it sizes the wrapper and the input fills it.
ShowClearButtonboolfalseAdds a × button inside a single-line box whose type is text. It shows while the box has focus and holds text; clicking it empties the box and raises ValueChanged with the empty text.
EnabledbooltrueFalse renders disabled. There is no ReadOnly parameter; a readonly attribute passes through to the input.
MaxLengthint?nullWrites maxlength. A client-buffered commit is also cut to this length.
InputTypestring"text"The input's type: email, tel, password and so on. Ignored when Multiline; an explicit type attribute wins except for a password box.
MultilineboolfalseRenders a <textarea> instead of an input.
Rowsint?nullWrites the rows attribute: the visible lines of a multi-line box.
UpdateOnInputboolfalseRaise ValueChanged on every keystroke instead of when the field changes.
TypingBehaviorTextBoxTypingBehaviorTextBoxTypingBehavior.ServerBackedClientBuffered keeps keystrokes in the browser and sends the whole value when the box loses focus; see the values table.
UncontrolledbooltrueThe browser owns the text, so a parent re-render never writes older text back over what is being typed. False gives the controlled input whose value follows Value on every render.
ReseedOnOutsideChangebooltrueWhen the parent sets a different Value from code, a browser-owned box shows it. Grid editors that push values through their own channel set this false.
AutoFocusboolfalseFocuses the box after the first render and writes autofocus.
SelectOnFocusboolfalseWith AutoFocus, that first focus selects the text. On a later focus the control asks its script to select, and the script skips this whenever the text differs from the element's value attribute, which Blazor does not write, so a box holding text is not selected.
ReplaceOnFirstInputboolfalseAfter the box gains focus, the first character typed replaces the whole text and the first Backspace or Delete clears it. A click inside the focused box cancels this.
SelectAllOnDoubleClickboolfalseDouble-click asks the script to select the whole text; the same value-attribute check as SelectOnFocus skips it for a box holding text.
UseClassicContextMenuboolfalseReplaces the browser's right-click menu with the control's own Windows-style menu.
ContextMenuItemsTextContextMenuItemsTextContextMenuItems.LegacyThe items the classic menu shows; see the values table.
KeepNativeTabboolfalseFor ClientBuffered with an OnKeyDown handler: Tab commits and is reported once, but the browser still moves focus. Grid cell editors leave it false.
TypingKeysStayLocalboolfalseKeydown events for printable keys, Backspace and Delete are not sent to the server; the text itself still is. Not used with ClientBuffered. For browser-owned editors whose host ignores typing keys, such as the grid's cell editor.
HtmlAttributesDictionary<string, object>?nullMore attributes for the input, merged after the unmatched ones.
ElementReferenceCapturedAction<ElementReference>?nullCalled after each render with the input's ElementReference.
AdditionalAttributesIDictionary<string, object>?nullCaptures unmatched attributes (id, aria-label, readonly…) and writes them on the input.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.