Web · Components
TagInput
Tag input: turns typed text into tags with Enter or a comma.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Email recipients: split by space/comma/semicolon, validate
Hashtag: # is removed, only letters/digits/dashes, color by tag
- #urgent
- #design
- #frontend
Team members: from the list only, search on the server
Read only
- Turkish
- English
- Deutsch
Import
Tag input: turns typed text into tags with Enter or a comma. For multiple free values like tags, email recipients, keywords, skill lists.
- Fast entry: Enter, comma (or
separators) complete a tag; pasting"a, b, c"or rows from Excel adds them all at once. Works on Android keyboards too (it looks at the text, not the key). - Validation:
max,maxLength,pattern,validate, duplicate check. Text that can't be added stays in the box with the reason below; a tag added again is shown with a short highlight. - Suggestions: With
items/loadItems, the list ofAutocomplete(virtualization, server search, highlighted matches); added ones don't appear in the list.allowCustomValue={false}allows only suggestions. - Editing: Double-click a tag or press Enter to fix it in place.
- Keyboard: In an empty box ← moves to the last tag; ←/→ between tags, Backspace/Delete remove. In an empty box Backspace first selects the last tag, a second press removes it (no accidental deletion).
- Form: With
nameeach tag is submitted separately (getAll),requiredworks, it resets with the form. For label, description and error seeTagField.
Examples
splitTags
functionSplits text at separators. Line breaks and tabs are always separators (pasting from Excel or a list). Empty pieces are dropped and edges trimmed.
Examples
sameTag
functionAre two tags the same? Case, Turkish character and accent differences are ignored.
checkTag
functionTells whether a tag can be added. index is the index of the already added tag for a "duplicate" result.
Examples
TagInputClassNames
interfaceClasses that can be passed to the inner parts of TagInput.
| Name | Type | Description |
|---|---|---|
control? | string | Frame wrapping the tags and the text field. |
input? | string | Text field. |
tag? | string | Each tag. |
message? | string | Row stating why a tag couldn't be added. |
content? | string | Panel where suggestions open. |
item? | string | Each suggestion. |
TagInputProps
interfaceProps of the TagInput component.
| Name | Type | Default | Description |
|---|---|---|---|
variant? | FieldVariant | CustomVariant<"field"> | Look: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, otherwise outline. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
value? | readonly string[] | Tags in controlled use. | |
defaultValue? | readonly string[] | Initial tags in uncontrolled use. | |
onValueChange? | (tags: string[]) => void | Called when tags change (add, remove, edit, clear). | |
onTagAdd? | (tag: string, item: SelectItem | undefined) => void | Called when a tag is added (with its item if picked from suggestions). | |
onTagRemove? | (tag: string) => void | Called when a tag is removed. | |
onReject? | (text: string, reason: TagRejectReason, message: string) => void | Called when a text can't be added as a tag. The message is already shown below the box; this is for your own notification or metrics. | |
items? | SelectItemsSource | Suggestions: an array, a Promise or a function called once. Filtered while typing; added tags don't appear in the list. Same format as Select. | |
loadItems? | SelectLoader | Function that searches suggestions on the server. See Select loadItems. | |
allowCustomValue? | boolean | true | Whether text not in the suggestions can also become a tag. When off, only suggestions can be picked (e.g. registered users). Always on without suggestions. |
separators? | readonly string[] | [","] | Separators that complete a tag while typing. Enter always completes; when pasting, line breaks and tabs are separators too. To separate by space, [",", " "]. |
max? | number | Maximum number of tags; if given, a 3/10 counter shows in the box. | |
maxLength? | number | Maximum number of characters in a tag. | |
pattern? | RegExp | Pattern the whole tag must match (e.g. /^[a-z0-9-]+$/). | |
validate? | TagValidator | Extra validation: return false or the message to show if invalid. | |
transform? | (text: string) => string | Transforms the text before adding (e.g. lowercase, removing #). Surrounding whitespace is already trimmed. | |
allowDuplicates? | boolean | false | Whether the same tag can be added several times. When off (ignoring case and locale-specific character differences), a tag added again is shown with a short highlight. |
addOnBlur? | boolean | true | Whether typed text becomes a tag on blur. |
editable? | boolean | true | Whether tags can be edited in place on double-click (Enter/F2 on the keyboard). |
tone? | Tone | ((tag: string) => Tone) | "neutral" | Color of the tags; a function for per-tag color ((tag) => tag === "urgent" ? "danger" : "neutral"). |
renderTag? | (tag: string, item: SelectItem | undefined) => ReactNode | Draw the tag content yourself (e.g. avatar + name). The remove button and keyboard behavior are kept. | |
inputValue? | string | Text in the text field in controlled use. | |
onInputChange? | (text: string) => void | Called when the text in the text field changes. | |
placeholder? | string | Text shown while the box is empty. | |
emptyMessage? | ReactNode | Content shown when no suggestion is found. | |
icon? | IconProp | Icon at the start of the box (e.g. "tag"). | |
clearable? | boolean | true | × button clearing all tags. |
name? | string | Form field name; each tag is submitted separately under this name (formData.getAll(name)). | |
form? | string | Id of the form the field belongs to (if outside the form). | |
required? | boolean | The form can't be submitted without at least one tag. | |
disabled? | boolean | Disabled. | |
readOnly? | boolean | Tags are visible but can't be added or removed. | |
id? | string | Id of the text field; <Label htmlFor> links to it. | |
autoFocus? | boolean | Focuses when the page opens. | |
tooltip? | TooltipProp | Tooltip shown when hovering the box. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | TagInputClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name if there is no visible label. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. TagField passes it itself. | |
aria-invalid? | boolean | "true" | "false" | Show the field as invalid. TagField passes it itself. |
TagRejectReason
typeWhy a tag wasn't added.
TagValidator
typeTag validator. Returns true (or nothing) when valid, false or an error message to show when invalid.
Examples
TagRules
interfaceOptions of splitTags and checkTag.
| Name | Type | Description |
|---|---|---|
separators? | readonly string[] | Separators; split text into tags while typing or pasting. |
max? | number | undefined | Tag count limit. |
maxLength? | number | undefined | Maximum characters of a tag. |
pattern? | RegExp | undefined | Pattern the whole tag must match (e.g. /^[a-z0-9-]+$/). |
validate? | TagValidator | undefined | Extra validation. See TagValidator. |
allowDuplicates? | boolean | undefined | Can the same tag be added more than once? |
TagCheck
typeResult of checkTag.
| Name | Type | Description |
|---|---|---|
ok | true | false | The tag can be added. |
reason | TagRejectReason | Rejection reason.({ /** The tag cannot be added. */ ok: false; /** Rejection reason. */ reason: TagRejectReason; /** Error text returned by the `validate` rule. */ message?: string; /** Index of the already added tag for a `"duplicate"` result. */ index?: number; }) |
message? | string | Error text returned by the validate rule.({ /** The tag cannot be added. */ ok: false; /** Rejection reason. */ reason: TagRejectReason; /** Error text returned by the `validate` rule. */ message?: string; /** Index of the already added tag for a `"duplicate"` result. */ index?: number; }) |
index? | number | Index of the already added tag for a "duplicate" result.({ /** The tag cannot be added. */ ok: false; /** Rejection reason. */ reason: TagRejectReason; /** Error text returned by the `validate` rule. */ message?: string; /** Index of the already added tag for a `"duplicate"` result. */ index?: number; }) |