Inputs
TextField
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
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.
Password
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.
Binding
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.
[]
[]
Clear button
Character count
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.
Mask
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.