Inputs
TagsInput
The TagsInput turns free text into a list of short values: the user types a tag, confirms it with Enter (or with a separator of your own), and it becomes a removable chip in front of the input. It binds to a collection of strings, offers known values through the browser's own suggestion list - or accepts nothing else - splits a pasted list into a tag each, and keeps the entries in shape on the way in: trimming, transforming, capping their length and their number, and rejecting the ones that repeat, that are too short, that fail a pattern or that a validator turns down, each rejection reported with the rule that caused it. The chips form a proper accessible list: one stop of the tab order that the arrow keys walk through, removable with Delete, correctable in place, movable by drag, by two taps on the handle a chip grows or with Alt and the arrows, with the ones a predicate pins in place carrying no dismiss button at all, and with every change announced to screen readers. It comes in three sizes, three variants and the whole accent palette, folds a long list away behind a chip, carries a label, a helper text, a prefix, a suffix, a counter, a clear button and a spinner for the suggestions it is still fetching, can be driven entirely from code, and takes part in an EditForm like any other input.
Keyboard, accessibility & templates
Keyboard navigation and typing, the live announcements and their localization, prefix and suffix texts, and tag templates with accessible names and per-tag styles.
Keyboard & typing
From the input, Backspace on an empty field removes the last tag - NoBackspaceRemove turns that off and BackspaceEditsLastTag turns it into a correction, putting the tag's text back into the input instead of letting it disappear - and the backwards arrow walks into the last chip. Tab commits the text left in the input unless NoAddOnTab is set, while Shift+Tab always walks straight out, so the field is never a trap. Losing the focus commits too, which NoAddOnBlur turns off and ClearOnBlur turns into a discard. While an input method is composing a character the Enter that picks a candidate is not treated as a confirmation, so a tag is never cut in half by it.
InputMode and EnterKeyHint decide the virtual keyboard a phone opens and the label on its return key; SpellCheck turns the red underline back on for a field that collects words rather than identifiers, and AutoComplete hands the browser's own autofill back where the field collects values it knows about.
Accessibility & localization
{0} for the tag - the move also
{1} for the position it landed on and {2} for how many tags there are, the
refusal {1} for why it was turned down - and an empty string keeps that event silent. The
two standing for a batch count instead of naming: reading fifty names out is not a confirmation but a
wall, and the tags are in the list to be walked through anyway.
The list itself sits away from the caret, so a reader landing in a field that already holds tags would otherwise be told only that the input is empty: the input describes itself with how many there are - "3 of 5 tags" where MaxTags sets a ceiling - which TagCountAriaDescriptionFormat writes. It is referenced rather than announced, so it is read on arriving and never while the field is being typed into.
The names of the parts follow the same idea: TagsAriaLabel names the list, TagAriaDescription is the sentence telling what the keyboard can do with the chip just reached (built from the gestures the field was actually given, and left out when there are none), DismissAriaLabelFormat and DismissTitle name the dismiss button, ReorderAriaLabelFormat, ReorderDropAriaLabelFormat and ReorderTitle the reorder handle, EditAriaLabelFormat the little edit input, and ClearButtonAriaLabel the button that empties the field. Each chip also carries its own position in the whole list, so "the third of six" stays true where MaxDisplayedTags folded the rest away.
One thing a chip cannot give on its own is a 24 CSS-pixel pointer target (WCAG 2.2, SC 2.5.8): the dismiss button and the reorder handle take the full height of the chip and a pad on either side of the glyph, which is all a chip as tall as a line of text has to give. Where that minimum has to be met, grow the chips -
--bit-TagsInput-tag-min-height: 1.5rem with a roomier
--bit-TagsInput-tag-padding - and widen the buttons through
Classes.DismissButton; the keyboard reaches both at any size, Delete removing the
focused chip and Alt with the arrows moving it.
Prefix & Suffix
To: of a recipients field, the unit of a list of
measurements. The prefix sits in front of the chips and the suffix after everything else, the clear
button included. Both are announced with the field - the input references them, ahead of the
Description - so a reader is told what a sighted user reads inside it.
PrefixTemplate and SuffixTemplate take markup instead, for an icon or a badge; markup
is as likely to be a glyph as a word, so those are not announced and what they mean has to be
in the Label as well.
Tag template & per-tag styling
[email protected] is announced by neither
the one nor the other: GetTagName is what names it, and the name it gives is carried by the
chip, by its dismiss button, by its reorder handle, by its inline edit and by every announcement the
tag takes part in. GetTagClass and GetTagStyle are what tell one
chip apart from the next: each receives a tag and returns what that particular chip should carry on top
of the shared styling - the address that is not well formed drawn in red, each priority in a color of
its own. They run for every drawn tag on every render, so they belong to a lookup rather than a
computation, and an exception thrown out of one leaves that chip looking like all the others.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.