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.
Suggestions & rules
Suggestions and restricting the tags to them, the count and length limits with the counter, and transforming, matching, validating and de-duplicating tags.
Suggestions
datalist - reachable, positioned and announced on every platform without a
popup of our own. Picking one only fills the input; the usual Enter turns it into a tag, so every rule
still applies. Values already in the list are left out, and so are all of them once MaxTags
leaves nothing to add. A datalist suggests rather than restricts: RestrictToSuggestions is what
makes them the only accepted values, rejecting anything else with the NotSuggested reason. What
counts as one of them is decided by Comparison, and the tag that is stored is the suggestion
rather than the spelling it was typed with, so a list to be grouped later never holds two spellings of
one value. MaxSuggestions caps how many are written into the page at once - beyond it only the
values holding what is being typed are kept, matched without regard to case the way the browser
filters the list it is handed, so what the user is shown does not change.
Where the catalogue is fetched rather than held, OnInput is what triggers the fetch and
Loading draws the spinner that says the field is waiting - an indeterminate progressbar, so
a screen reader hears the wait instead of missing it. DebounceTime waits for the typing to
stop before raising it, which turns a request per keystroke into a request per word
(ThrottleTime spaces them out instead, for a list that should keep up while the word is
still being typed). Only the callback waits: the text itself is tracked as it is typed, so the tag
Enter commits is never a keystroke behind, and the emptying that follows a committed tag is
reported at once, taking the pending call down with it.
Limits & counter
Rules & normalization
#, collapsing whitespace - so every rule below sees the normalized text and it is
the normalized text that is stored. Pattern is a regular expression every tag has to match (an
expression that cannot be compiled is ignored rather than breaking the field, and a runaway match is
timed out and treated as a failure); Validator covers what an expression cannot - a lookup, a
checksum, a rule depending on the other tags. A tag already in the list is refused by default and
reported through OnTagExists; Duplicates lifts that, and Comparison decides which
tags count as the same one. Every refusal reaches OnInvalid with the rule that caused it.
A refusal is never silent. ShowInvalidMessage draws why under the field, where the helper text stands - the same sentence screen readers are given, naming the limit the rule was built on ("A tag must be at least 3 characters.") rather than leaving the user to guess; a red rule alone is a message half the readers of a page never get. GetInvalidMessage rewrites that sentence for wording of your own and for localization, and InvalidAnnouncementFormat writes the frame it sits in (
{0} the tag, {1} the reason). Alongside it the field wears its
invalid color - and says so through aria-invalid - until the next keystroke answers it,
and a tag refused as a duplicate marks the chip already in the list that it collided with, since "you
already have this one" is only an answer if it says which one. NoInvalidHighlight turns that
mark off, and OnInvalid (with OnTagExists for the duplicate alone) hands the refusal to
a report of your own.
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.