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.

Customization

Defaults through BitParams, the color, external icons, sizes, Style & Class with the CSS variables, and right-to-left fields.

Cascading parameters

BitParams carries a BitTagsInputParams down to every tags input under it, so a form, a panel or a whole page sets the shared look, the shared separators and the shared rules once instead of on every field. What it carries is a default and not an override: a field that writes a parameter for itself keeps its own value, and only what it left unset is filled in from the cascade. What travels down is the configuration and never the value - Value, DefaultValue, Name, Required and ReadOnly belong to the one field that holds them, as do the templates and the event callbacks.

blazor
1 tags.
dotnet
1 tags.

Color

Color picks the role the component carries: the tags are painted with it, as much of them as the TagVariant asks for, and so are the border and the focus ring of the focused field. The error state of a failing validation always wins over it, which keeps an invalid field recognizable whatever its color is.

tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.
tag
1 tags.

External Icons

The dismiss button of each tag and the clear button of the field take their icon either from the built-in Fluent UI set, through DismissIconName and ClearButtonIconName, or from any external library through DismissIcon and ClearButtonIcon, which take a BitIconInfo built by BitIconInfo.Fa (FontAwesome), BitIconInfo.Bi (Bootstrap Icons) or BitIconInfo.Css (any CSS classes at all). The BitIconInfo wins when both are given.

blazor
dotnet
2 tags.
blazor
dotnet
2 tags.
blazor
dotnet
2 tags.

Size

Size scales the field, the chips and the text inside them together. An empty field takes the control height of its size class, so it lines up with the text fields and pickers beside it in a form, and grows from there with every line of chips that wraps into it.

blazor
dotnet
2 tags.
blazor
dotnet
2 tags.
blazor
dotnet
2 tags.

Style & Class

Style and Class reach the root element only, while Styles and Classes reach every part by name - the label, the description, the sentence a refusal is reported with, the counter, the input container, the affixes, the wrapper of the tags, each tag and its text, the reorder handle and the dismiss button with their icons, the fold chip, the input, the little edit input, the loading spinner and the clear button - plus the state slots Focused, FocusedTag, FixedTag, EditingTag (the chip being corrected), PickedUpTag (the chip waiting to be put down) and DuplicateTag (the chip a refused duplicate collided with). Prefer Classes when your CSS should own states such as hover, which inline styles cannot express.

Component's Style & Class:
blazor
1 tags.
blazor
1 tags.

Styles & Classes:
blazor
dotnet
Every part of the component has a slot of its own.
2 tags.
blazor
dotnet
Every part of the component has a slot of its own.
2 tags.


The component also reads a set of CSS variables off its elements. They inherit, so a value on :root or any ancestor re-skins every tags input below it, and one on the Style of an instance re-skins that one and any tags input nested in it. They restyle the default, not a choice: an explicit Color or Size wins over the variables for what it sets.

CSS variables:

blazor
a-very-long-tag-that-does-not-fit
dotnet
3 tags.
design
system
2 tags.
blazor
1 tags.

Set once on an ancestor, inherited by every field inside it:

blazor
1 tags.
dotnet
1 tags.

RTL

In a right-to-left direction the chips are laid out from right to left and the arrow keys swap along with them, so the key pointing at the visual left still walks towards the tag drawn there. The value keeps its logical order: the first chip is always the first tag of the list.

بلیزر
دات‌نت
با کلید Enter برچسب را ثبت کنید.
2 tags.
بلیزر
دات‌نت
2 tags.

Feedback

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