Tags Autocomplete is used to select one or multiple values from a list and to input custom values.
When focusing on the field, the dictionary menu opens. Autocomplete changes as you type. Selecting an option from the list adds a tag, clears the text in the field, and closes the menu.
The menu belongs to autocomplete — its width is configured there, through the panelWidth and panelMinWidth attributes of <kbq-autocomplete>, and is measured against the whole field rather than the input.
Search splits a multi-word query into parts and searches for them independently, trims leading and trailing spaces, is case-insensitive, and folds diacritics. The algorithm is described in the Smart search guide.
The option to create a new tag is placed first in the autocomplete menu. It creates a new token from the entered text if it doesn't exist in the dictionary.
Adding a tag also works with the Tab key.
Creating a duplicate of a selected tag is not allowed: the system will show the message Nothing found.
Tag removal order:
Tags can be removed in several ways:
kbqTagRemove directive) inside the tag.Delete or Backspace key.The removal option is configured using the removable attribute (enabled by default).
Tags can be selected in several ways:
Ctrl.Shift to change the selection range from the anchor tag to the clicked tag.Shift + ← / → to expand or shrink the range.Ctrl+A key combination.Space when the tag is focused.Pointer and keyboard interactions change the same range relative to its initial tag. When the range shrinks, tags outside it are deselected. Disabled tags remain unchanged.
The selection option is configured using the selectable attribute (enabled by default).
To enable editing mode, you need to set the editable property for kbq-tag-list or individual kbq-tag.
Enter editing mode:
Enter or F2 key (when tag is focused).Save changes:
Enter key.kbqTagEditSubmit directive).Cancel changes:
Escape key.In editing mode, the tag transforms into an input field and remains at the same position within the control.
To enable tag reordering, you need to set the draggable property for kbq-tag-list.
Validators belong on <kbq-tag-list>: the tag list is the form control for the whole set of tags, while the input is only a text entry helper.
A [formControl] or [ngModel] of its own on <input kbqTagInputFor> is still required here: kbqAutocomplete drives the input through it, and without it panel filtering and typed-text tracking break. The library simply does not consider validators attached to that control.
The control value is the array of tags, so a single set of validators covers both the number of tags and the content of each one. Validation applies equally to tags picked from the autocomplete panel, typed by hand and pasted from the clipboard.
Validators do not prevent a tag from being added: the tag is added and the field goes into the error state. To keep an invalid value out of the list, filter it in the (kbqTagInputTokenEnd) and (optionSelected) handlers.
When the error becomes visible is controlled by ErrorStateMatcher, and by default happens once the control is invalid and either touched or the form has been submitted.
Key |
Action |
|---|---|
| Backspace / ← / Shift + Tab | Move focus to the last tag. |
| Ctrl + A | Select all tags and set focus to the last one. |
Key |
Action |
|---|---|
| ← / → | Move focus to previous/next tag. |
| Shift + ← / → | Change the range and move focus. |
| Space | Select/deselect tag. |
| Delete / Backspace | Remove tag. |
| F2 / Enter | Start editing. |
| Ctrl + A | Select all tags. |
| Home / End | Move focus to first/last tag. |
Key |
Action |
|---|---|
| Enter | Save changes. |
| Esc | Cancel changes. |