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.

Input, buttons & masks

The icon, prefix and suffix, revealing a password, binding with immediate, debounced and throttled updates, the clear button, the character counter, and input masks.

Icon & affixes

An icon and the two affixes - a prefix and a suffix - sit inside the frame beside the input. IconName renders a glyph of the built-in Fluent UI set, and IconPlacement decides which end it takes: End by default, past the clear and reveal buttons, or Start in front of the input, where the mark that says what a field is for belongs. Prefix and Suffix are static pieces of text on either side and are not part of the value - a field with an https:// prefix still binds only what was typed - so keep a descriptive label on the field, since a screen reader reads the value without the affixes around it.

All three follow the reading direction rather than the screen, so they mirror themselves in a right-to-left page. The icon is decorative by default - hidden from screen readers and not focusable - and one that carries a meaning of its own gets a name through IconAriaLabel, shown in the Accessibility section. It picks up the Accent color while the field has focus, and the whole frame shows a text cursor and means it: a press on an affix, on the icon or on the busy indicator puts the caret in the input.

OnIconClick turns the icon into an action instead - opening a picker, copying the value, running a search. Giving it a handler renders the icon as a real button: it takes a tab stop, answers Enter and Space and draws a focus ring of its own, so pair it with an IconAriaLabel that says what pressing it does, and with an IconTitle for the tooltip. It keeps working on a read-only field, since an action the icon stands for is not an edit, and it is disabled along with the field.



https://

.com

https://
.com

$
USD

https://
.com

The icon was pressed [0] times.

Password

Type="BitInputType.Password" masks the value. Adding CanRevealPassword renders a toggle button that swaps the input to plain text, which is the pattern that lets people check what they typed instead of typing the password twice. The button keeps one stable RevealPasswordAriaLabel in both states and reports the current state through aria-pressed, which is what screen readers announce reliably; the caret is handed back to the input after every toggle. RevealPasswordIconName and HidePasswordIconName customize the two icons, and the native reveal affordance that Edge and Internet Explorer add to a password input is taken away so that only one of them is ever shown. The ToggleRevealPassword method drives the same toggle from the outside - from a checkbox next to the form, for instance - and is ignored unless the field is a revealable password, so a revealed value can never survive the reveal being taken away. Pair the field with an AutoComplete of current-password or new-password: it is what tells a password manager whether to offer the saved credentials or to generate a new one, and it is the difference between a sign-in form that fills itself and one that fights the browser.



AutoComplete tells the browser which credential belongs here.


Binding

The value is committed on the change event by default, which for a text field means when it loses focus. Immediate switches to the input event so every keystroke updates the bound value; on top of it, DebounceTime waits until the typing pauses for that many milliseconds before committing, and ThrottleTime commits at most once per that many milliseconds - both of them are what a search-as-you-type field wants so it does not fire a request per character. DefaultValue seeds an uncontrolled field that reports through OnChange instead of a two-way binding. An Immediate field also guards against the input method editors used for Chinese, Japanese and Korean: the half-composed characters a candidate window produces are kept out of the bound value, which only receives the text once the composition is committed.

Trim strips the leading and trailing whitespace off whatever is committed, which is what keeps a stray space from being saved along with an email address or a coupon code. It runs on the change event rather than on every keystroke, so a space can still be typed in the middle of a word while Immediate is on, and it leaves a DefaultValue alone, since that one is assigned as it is given.

Whatever the field ends up holding is what is left on screen: a trimmed value, and the old value of a Value bound without a ValueChanged or an OnChange, are both written back into the input, so the text under the caret is never something the field is not actually holding.

Value: []

Value: []


Value: []

Value: []

Value: []

Value: []

[]

[]

Clear button

ShowClearButton renders a button that empties the field, and it only appears while there is something to clear - from the very first keystroke, since it follows what the input holds rather than the bound value, which on a field without Immediate is only committed on blur. Clearing sets the value to null through the normal binding, fires OnClear and returns the focus to the input so typing can continue right away. The button is a real button with an ClearButtonAriaLabel, so it is reachable by keyboard, and it is disabled in the read-only and disabled states. ClearButtonIconName swaps its icon, and it works in the multiline mode too. Emptying a field moves nothing and says nothing on its own, so the field announces it through its live region - ClearedAnnouncement is what that announcement says instead of the default "Cleared", and an empty string keeps it silent. ClearOnEscape puts the same clearing on the Escape key, which is what a filter or a search field is expected to do; it needs no button of its own, leaves a read-only field alone, and lets Escape keep its meaning while an input method editor is composing. A search input draws a clear affordance of its own in WebKit browsers, which is hidden while the clear button is on so that the field never shows two of them. The ClearAsync method does the same thing from code - without needing the button to be visible at all - and raises OnClear just like a click on it does.








Value: [Clear me from the button below]

Character count

ShowCount renders a counter under the field. With a MaxLength it reads typed/limit and is pointed at by aria-describedby, so a screen reader announces the limit along with the field; without one it is just the number of characters typed so far. The counter follows the keystrokes directly rather than the bound value, so it stays live even when Immediate is off and the value is only committed on blur. CountTemplate replaces the whole text with content of its own, shown in the Templates section. A count above the limit turns red: the keyboard cannot get there, since MaxLength renders the html maxlength attribute, but a value assigned from the code can, and a counter reading a number above its own limit in the muted grey of a valid one would say nothing about it.

By default the characters are counted the way the browser counts them against the limit - in UTF-16 code units - which makes an emoji count as two and a family emoji as eleven. CountStrategy replaces that with a count of your own, most often StringInfo.LengthInTextElements, which counts what a reader actually sees. It only changes the number that is shown: the maxlength attribute keeps holding the keyboard back at its own count, so a strategy that counts fewer characters than the browser does reaches the limit before the counter says so.

0/30

0

Both the description and the counter share the footer.
0/30

42/10

0/140
Value: []

7/20

The same value, counted the way it reads.
4/20

Mask

Mask lays the text out as it is typed: # takes a digit, A a letter and * either, every other character is inserted for the user, and a backslash makes the next character a literal. The caret stays where it was as the literals move around it. The value is the formatted text, or with MaskRawValue only what went into the slots.

Value:

Value:


Feedback

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