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.

Accessibility & validation

Placing the label around the input, the busy indicator, naming and describing the field for assistive technologies, and validation with its error messages.

Label position

LabelPlacement moves the label around the input: Top is the classic form layout, Bottom puts the caption under the field, and Start and End lay the two out on one line, which is what a compact settings row or a filter bar wants. The two row layouts follow the reading direction rather than the screen, so they mirror themselves in a right-to-left page. Leaving the parameter unset keeps the layout each variant comes with - above the input in the default one and next to it in the underlined one - so an existing field never moves on its own.





The footer keeps its own line under the whole row.
0/20

The underlined variant lays its label out in a row of its own, and an explicit position takes that row apart.

Loading

Loading shows a busy indicator inside the field, which is how a field says that something is running against what was typed - a suggestion being fetched, a name being checked for availability, a value being validated on the server. The field stays fully editable while it is on, so the typing is never interrupted. The input carries aria-busy while it is on, which is what tells an assistive technology that what it is reading is still being worked on, and a polite live region that is always part of the field announces that it started - politely, so it waits for the reader to finish the sentence it is on rather than cutting into it. LoadingAriaLabel is what that announcement says instead of the default "Loading", and LoadingTemplate replaces the spinner with any content - one of the other loading components of the library, an icon, a piece of text - without costing the field its announcement.

Loading

Loading

Loading
Checking the availability

Accessibility

A field is only usable by everyone when what it expects is exposed to assistive technologies as well as to the eye. Label is the first tool for that and should be preferred over AriaLabel, which names the input for a screen reader without showing anything - use it only where the surrounding layout already makes the purpose obvious. Setting both is allowed and the AriaLabel wins: the visible caption keeps labelling the field for the eye and for the click that focuses it, while the screen reader is given the fuller name. Description is the visible hint under the field, while AriaDescription is a hidden one for the cases where the instruction would be too long to show; both are referenced by the input through aria-describedby, in reading order, alongside the error message that comes first when there is one and the character counter when it carries a limit. An aria-describedby of your own, passed through InputHtmlAttributes, is kept and read first rather than replaced, which is what lets a field point at an error message the app renders next to it and still keep its own description. An aria-labelledby of your own is kept the same way and names the field instead of the visible label, which is what a field labelled by a heading or a table column header needs. Title renders the html title of the field, which the browser shows as a tooltip on hover. The trailing icon is decorative and hidden from screen readers by default; IconAriaLabel turns it into an image with a name for the cases where the icon carries a meaning of its own. The placeholder is painted from the theme rather than left to the grey the browser picks, which fails the contrast floor on a dark surface - but it still disappears the moment anything is typed, so it never carries what the Label and the Description should.

The field keeps one polite live region of its own, which is what carries the things that happen away from the caret: a rejection that arrives while the field still has focus, the busy state, an inline suggestion, and the emptying of the field by the clear button - ClearedAnnouncement is what that last one says. They are announced politely, so none of them ever cuts into what is being read. AutoComplete is what says which piece of personal information a field collects, which a browser, a password manager and an assistive technology all read; a field asking for a name, an address, an email or a credential wants one (WCAG 2.2, Identify Input Purpose).

In Windows High Contrast the whole palette collapses to the system pair, which would take four of the states of the field with it: the disabled field is redrawn in the system grey, the rejected frame becomes a dashed one rather than a red one, the ghost suggestion keeps reading as a suggestion instead of as text already in the value, and a field that deliberately has no frame is given one back, since there is nothing else left to say where it is.

Card number
Use the number printed on the back of your card, without the spaces between the groups.





Card number
The field also points at this element, which is not a part of it.

Shipping address
Named by the heading above it rather than by a label of its own.

Validation

Inside an EditForm the field joins the cascading EditContext automatically, so the data annotations on the model drive it: a failing field gets the bit-inv class and the aria-invalid="true" attribute, and the state is refreshed on every validation pass. Its root also carries the classes the framework's own inputs take from the EditContext: valid or invalid, with modified once the field has changed - or the names of a FieldCssClassProvider set with EditContext.SetFieldCssClassProvider - so a stylesheet written for those styles the field too. They sit on the root, around the label and the messages, rather than on the native input. Use NoValidate to opt a field out of the EditContext altogether, and DisplayName to control the name used in the generated messages.

Not every rejection comes from a data annotation, though - a name a server reports as taken, a rule that needs two fields to be compared, a field that lives outside any form at all. Invalid forces the same state from the outside: the same red frame, the same focus ring and the same aria-invalid, without an EditContext being involved. It only ever adds to the validation of the field, so a value the EditContext already rejected stays invalid whatever the parameter says.

ErrorMessage is what turns that red frame into something the reader can act on: the text is rendered under the field, above the description and the counter, and setting it marks the field invalid on its own - there is no need to also set Invalid. It is referenced by the input through aria-describedby ahead of the description, and announced by the live region of the field the moment it shows up, so a rejection that arrives while the field still has focus is not something only sighted users learn about. ErrorMessageTemplate replaces the text with content of its own, shown in the Templates section. Both are meant for the rejections the app knows about.

Inside an EditForm, ShowValidationMessage puts the messages of the data annotations in that same place, so the form below needs no ValidationMessage component beside each field. The input is described by them through aria-describedby, so they are read out when the field takes the focus, and an ErrorMessage of the app's own wins the place while it is set. Unlike an ErrorMessage they are not announced as they appear: a submit validates every field at once, and a message from each of them read out in a row would bury the form under its own errors. A BitParams holding a BitTextFieldParams with ShowValidationMessage turns it on for every field inside it.


Anything without a space in it is rejected.


That user name is already taken.
That user name is already taken.

A user name cannot contain a space.
Letters and digits only.
8/20
A user name cannot contain a space.

'not-an-email' is not an email address.
The message shows up as soon as the value stops looking like an email address.
'not-an-email' is not an email address.







Feedback

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