Forms
TwTagInput
TwTagInput is a Blazor tag input for lists of free-form tags. Add tags with Enter or a comma, paste a whole list and get suggestions as you type.
Last updated
Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at
https://github.com/twblazor/twblazor/issues.
Basic usage
Bind the tags with
@bind-Value to an IReadOnlyList<string>. Type a tag and press Enter or type a comma to add it. Each tag is a removable TwChip: click its remove button, or press Backspace in the empty field to remove the last tag. Surrounding spaces are trimmed and empty tags are ignored.- Blazor
- C#
Value: Blazor, C#
Separators and paste
Separators are the characters that add a tag when typed, a comma by default. Pasted text is split on them and on line breaks, so a whole list can be pasted at once. Here a space, a comma and a semicolon all separate tags. Pass an empty list to add tags with Enter only, so a tag can contain commas.Separate keywords with a space, a comma or a semicolon, or paste a list.
Suggestions
Pass
Suggestions to list matching tags as the user types. The arrow keys move through them and Enter adds the highlighted one, or click one. Tags already added are left out, and any other text can still be added. For a server-side search, set SearchFunc instead, with DebounceInterval to wait for a pause in typing.- Blazor
Limits and duplicates
MaxTags caps how many tags the field holds and MaxTagLength how long each one can be. Duplicates are rejected, ignoring case, unless AllowDuplicates is set. A tag that cannot be added stays in the field, the reason is shown under it and announced, and OnTagRejected is invoked with the tag and a TagRejectionReason.- bug
Up to 3 labels of at most 12 characters.
Last rejected: none
Validation
TagValidator checks each tag before it is added: return an error message to reject it, or null to accept it. Inside an EditForm or a TwForm the field reports every change, so validation attributes on the bound list, such as [MinLength], run for it and their message is shown under the field.Add on blur
Set
AddOnBlur to add the typed text as a tag when focus leaves the field, so a tag the user typed but did not confirm is not lost.- Flour
Clearable
Clearable shows a button at the end of the field that removes every tag. Like the text field's clear button it is not a Tab stop, since keyboard users can remove tags with Backspace.- Ada
- Grace
- Alan
Variants, dense and chip style
Variant and Dense work as they do on TwTextfield, so a tag input lines up with the other inputs; a dense field uses smaller tags. ChipColor and ChipVariant style the tags.- Design
- Code
- Design
- Code
- Design
- Code
Disabled and readonly
Disabled dims the field, and its tags can neither be added nor removed. ReadOnly keeps the tags readable, but hides their remove buttons and blocks typing.- Archived
- Internal
- Archived
- Internal
Accessibility
The tags are a list named after the field's
Label, placed before the text field, and each remove button is named after its tag, such as "Remove Blazor". Tab stops only on the text field: the arrow keys move between the tags, and Delete or Backspace removes the focused one, so a long list of tags does not fill the Tab order. Every tag added or removed is announced through a live region, in the language of the app. HelperText and any error message are linked to the text field with aria-describedby. In a right to left layout the arrow keys follow the reading direction.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwTagInputTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
Field |
string | |
Size |
string | |
DenseSize |
string | |
ChipsPadding |
string | |
TagList |
string | |
Input |
string | |
EndContent |
string | |
ClearButton |
string | |
HelperText |
string |
Full reference: TwTagInputTheme on the API docs.