UI Toolbox logoUI Toolbox
Support

TagField

A TagField is a text field whose entries become tags, shown as chips with a "×" button. Its value is the list of tags, an IReadOnlyList<string>.

A Tags field with the melee, fire, two-handed and rare chipsA Tags field with the melee, fire, two-handed and rare chips

<UIToolbox.TagField label="Tags" placeholder="Add a tag" max-tags="5" />
<UIToolbox.TagField
    label="Skills"
    suggestions="Archery,Alchemy,Smithing,Stealth"
    tags="Archery" />
var field = new TagField("Tags")
{
    MaxTags = 5,
    Suggestions = { "bug", "feature", "docs" }
};
field.AddTag("bug");
field.RegisterValueChangedCallback(evt =>
    Debug.Log(string.Join(", ", evt.newValue)));
Member Description
value The tags. A set trims each tag, drops the empty ones and the duplicates, and keeps the first MaxTags. The UXML value attribute takes the tags with commas between them, as tags does.
Tags (tags) The tags as a List<string>, for UXML. A set sends no change event.
MaxTags (max-tags) The most tags. 0 (the default) sets no limit.
AllowDuplicates (allow-duplicates) Lets the same tag in more than one time. Off by default. The comparison ignores case.
Placeholder (placeholder) The text shown while there is no tag and no typed text.
Suggestions (suggestions) The entries that show in a list under the field while the user types.
AddTag(string) Adds a tag as typing it and pressing Enter does. Returns false for an empty text, a duplicate, or a full field.
RemoveTag(string) Removes the first tag that equals the text, ignoring case. Returns false when there is none.
Text The text that the user typed and did not add yet.
IsSuggestionListOpen True while the list of suggestions shows.
Popup The list of suggestions, a ChoiceList: its Items and its Highlighted row.

Adding and removing

Suggestions

With Suggestions, a list opens under the field when the typed text matches an entry. The list leaves out the tags that the field has, unless AllowDuplicates is on.

Events

Each change of the tags sends one ChangeEvent<IReadOnlyList<string>>. A pasted text or an AddTag call is one change. Typing sends none. A tag that is refused (a duplicate, empty, or over MaxTags) sends none.

Shared parts

Styling

Class Element
tb-tag-field The field. tb-tag-field--focus is on it while the text or a chip has the focus.
tb-tag-field__box The box around the chips and the text.
tb-tag-field__input The text field.
tb-tag-field__chip A chip. tb-tag-field__chip--selected marks the chip that Backspace removes.
tb-tag-field__chip-text The text of a chip.
tb-tag-field__chip-remove The "×" button of a chip.
tb-tag-field__popup The list of suggestions.

The chips look like the chips of SearchDropdown. Use tb-field--error on the field for the error border.

The TagFieldDemo scene shows a filter for the items of a bag, the skills of a character with suggestions and a limit, and the runes of a spell, where a rune can come twice.