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.
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
Loading
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.
Accessibility
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.
Validation
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.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.