Skip to content

Inputs

TagsInput

Bit.BlazorUIChipsTokens

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.

Managing tags

Correcting tags in place, reordering them by drag, tap or keyboard, folding the extra tags away, the clear button, and tags that cannot be removed.

Editable tags

EditableTags lets a tag be corrected in place instead of being removed and typed again: double click a chip, or press Enter or F2 on the focused one, and it turns into a little input with its text selected - carrying the same InputMode, EnterKeyHint and SpellCheck as the field, since those belong to the values it collects rather than to the one box they are typed into. Enter commits, Escape puts the old text back, and leaving the input commits too. The text goes through the same trimming, transformation and validation as a tag being added - except that the tag is not a duplicate of itself and the ceiling cannot be reached, since the list does not grow. A correction those rules turn down is handed back in the still open input, caret at its end, rather than being thrown away with the chip snapping back: an error is the one moment a field must not lose what was just entered. Committing an empty text removes the tag, and OnEdit receives the old and the new text and can call the change off.

blazor
dotnet
web
Correct one to a single letter: the refusal says why and hands the text back.
3 tags.
Press Enter to edit, or Delete to remove.

Reordering

AllowReorder lets a tag be moved three equal ways, one for each kind of user. Drag a chip onto the one whose position it should take: the carried chip fades and the one under the pointer is outlined, so the landing place is visible before the button is let go of. Tap the handle the chip grows at its start, then the tag whose place it should take - two taps rather than a drag, for every pointer that cannot drag at all: a touch screen, a switch, a head pointer. A second tap on the handle, on the lifted chip, on the field around it, or the Escape key puts it back down. From the keyboard, hold Alt with the arrow keys to walk the focused chip one position at a time, or Alt+Home / Alt+End to send it to either end. Whichever it was, the focus travels with the tag and the move is announced. ReorderIconName, ReorderTitle, ReorderAriaLabelFormat and ReorderDropAriaLabelFormat write the handle, and PickedUpAnnouncementFormat and PutBackAnnouncementFormat what it says out loud. OnReorder reports the tag and the two positions, which is what says which chip moved without diffing the list; the order is part of the value, so the move is written back through @bind-Value as well.

first
second
third
fourth
Drag a chip onto another one; or tap a handle and then the tag whose place it should take; or focus one with Tab and hold Alt while pressing the arrow keys.
4 tags.
Press Alt with the arrow keys to move, or Delete to remove.

Folding the tags away

MaxDisplayedTags draws only the first few chips and folds the rest behind one saying how many are left, which unfolds the list and folds it back - so a tag that is not drawn is never a tag that cannot be reached, with the pointer or with the keyboard, where the chip is a tab stop of its own. Only how much is drawn changes: the value keeps every tag, the counter counts all of them, and the form posts them. MoreTagsFormat and LessTagsText write its two labels, MoreTagsAriaLabelFormat what it is announced as - "+3" read out alone says nothing about what pressing it would do.

blazor
dotnet
web
The rest of the tags are one click away.
6 tags.
blazor
dotnet
4 tags.

Clear button

ShowClearButton renders a button at the end of the field that empties the whole list along with the text in the input, and raises OnClear with what it removed. It is not rendered while the field is read-only, disabled or already empty, and it stays out of the tab order - Escape on the input is its keyboard equivalent. Escape takes back what is being typed first, though: it is the second press, on the now empty input, that empties the list. OnBeforeClear runs first whichever of the three emptied the field and can call it off, which is where a confirmation belongs. Pressing the button takes the button away with everything else, so the caret is handed back to the input rather than dropped on the page. NoClearOnEscape hands the key back to whatever surrounds the field, for a form inside a modal or a callout where dismissing that is what the user means by pressing it.

blazor
dotnet
web
3 tags.
blazor
dotnet
web
Clearing is refused while there are more than two tags.
3 tags.

Fixed tags

CanRemoveTag decides which tags the user may take off the list, for the values a field holds but does not let go of: the owner among the editors of a document, the tag a saved filter is built on. A tag it turns down is drawn without a dismiss button, ignores Delete and Backspace, is left alone by the Backspace pressed on the empty input, and stays behind when the field is cleared - so clearing empties the field of everything it can be emptied of, and a field holding nothing else does not render a clear button at all. It is still editable and still movable, since neither takes the tag away, and the sentence announced after a fixed chip says so rather than promising a removal that does nothing. It governs what the user may do, not what you may: RemoveTagAsync names a tag outright and takes it off regardless.

[email protected] is the owner: no dismiss button, no Delete, and the clear button leaves it behind.
2 tags.
Press Enter to edit, or Delete to remove.
This tag cannot be removed. Press Enter to edit it.

Feedback

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