Skip to content

Inputs

TextField

Bit.BlazorUITextInputTextAreaPasswordField

Text fields give people a way to enter and edit text. They're used in forms, modal dialogs, tables, and other surfaces where text input is required. A single BitTextField renders either an input or a textarea, carries a label in any of the four positions around it, a visible or screen-reader-only description, a character counter and a message saying why the value was rejected, exposes every part of its chrome to templates and to the Styles and Classes parameters, wires its own labels and descriptions to the input through the aria attributes, and plugs into an EditForm the same way the built-in Blazor inputs do.

Templates & events

Templates for every part of the field, inline ghost-text suggestions, the events, and selecting the text on focus or from code.

Templates

Every piece of chrome around the input can be replaced by a template when the plain string parameters are not enough: LabelTemplate, DescriptionTemplate, PrefixTemplate and SuffixTemplate take over from Label, Description, Prefix and Suffix, ClearButtonTemplate replaces the icon of the clear button, RevealPasswordTemplate receives whether the password is currently revealed, CountTemplate receives the current number of characters, ErrorMessageTemplate replaces the rejection message under the field and marks it invalid just like the plain ErrorMessage does, and LoadingTemplate replaces the spinner of the busy indicator (shown in the Loading section). A field rendered through a LabelTemplate still gets the required asterisk, so custom chrome never costs the field its markings.








0 of 20 characters

✖ This name is reserved. See the Validation section.
Invalid input

GhostText

Ghost text is the faded completion an editor shows after what has been typed. Set GhostText from the outside - from an autocomplete list, from a model, from anywhere - and it is painted behind the input without ever entering the value. Pressing Tab or Enter with the caret at the end of the text, or clicking/touching the field there, accepts it: the text is inserted, the bound value is updated whether or not Immediate is on, and OnGhostTextAccepted fires with the accepted string so the suggestion can be cleared or replaced. Any other keystroke discards the suggestion, and a suggestion that would not fit under MaxLength is cut down to whatever room is left rather than pushing the value past the limit the keyboard cannot pass either. PermanentGhost reserves the scrollbar gutter of a multiline field so the text does not shift when the suggestion makes it overflow. The overlay itself is painted for the eye only and hidden from screen readers, so the suggestion is announced through a polite live region instead - without it an inline completion would be a feature only sighted users ever learn about. What the region says is the suggestion and nothing else, so pair the field with an AriaDescription saying how to take it ("press Tab to accept the suggestion").

Basic (non-async)
A completion may be suggested as you type. Press Tab to accept it.
Value: []

A completion may be suggested as you type. Press Tab to accept it.
Value: []


Advanced (async + cancellation)
A completion may be suggested as you type. Press Tab to accept it.
Value: []

A completion may be suggested as you type. Press Tab to accept it.
Value: []

Events

Besides OnChange, the field forwards the raw dom events it sits on: OnKeyDown and OnKeyUp for every key, OnEnter and OnEscape as shortcuts for the two keys a form cares about most, OnClick, and OnFocus, OnBlur, OnFocusIn and OnFocusOut for the focus lifecycle. The difference between the two pairs is bubbling: focus and blur are raised by the input alone, while focusin and focusout also reach it from whatever is inside it, which is what makes them the ones to watch when a whole group of controls is being tracked. All of them are skipped while the field is disabled. OnEnter and OnEscape are also skipped while an input method editor is composing, where the two keys commit and cancel a candidate rather than the value - so a form is never submitted in the middle of typing a Chinese or Japanese word.

OnInput is the one that fires on every input event, whichever way the text arrived - a keystroke, a paste, a drop, an autofill - which is what a strength meter or a live preview needs. Unlike OnChange it does not wait for the field to lose focus and it does not require Immediate, so it can watch the text without committing it, and it is raised before DebounceTime and ThrottleTime hold the value back rather than along with it. Like the rest of the events it stays quiet while an input method editor is composing, so it never sees a half-composed word.


Last event: []
Last key down: []
Last key up: []
Focus: []

Typed so far: []
Committed value: []

OnClear: []

Selection

SelectOnFocus selects the whole value the moment the field receives focus, so the next keystroke replaces it instead of appending to it - what a field holding a value meant to be overwritten rather than edited (a search term, a quantity, a generated code) usually wants. It applies to a read-only field too, where selecting the value is exactly what makes it easy to copy, and to an AutoFocus field, whose focus is given to it before anything could listen for it. The same thing is available from code through SelectAsync, and SelectRangeAsync selects only a part of the value, or moves the caret when the two positions are equal. Both positions are clamped to the length of the value, a null start counts from the beginning and a null end runs to the very end, so a range can never fall outside the text.




Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.