Skip to content

Tag Input

The Tag Input component allows users to enter multiple tags or keywords in a single input field. It supports autocomplete, custom tag separators, and various styling options.

  • input-common: Common input functionality
  • tag: The Tag component for individual tag styling
  • button: The Button component for action buttons
<input data-role="tag-input" data-tag-separator="," value="tag1, tag2, tag3">
<input data-role="tag-input" data-autocomplete="Ukraine, USA, Canada, Singapore, Morocco">
<input data-role="tag-input" data-random-color="true" value="tag1, tag2, tag3">
<input data-role="tag-input" data-label="Tags:" value="tag1, tag2, tag3">
<input data-role="tag-input" class="input-small" value="tag1, tag2, tag3">
ParameterTypeDefaultDescription
autocompleteArray/Object/StringnullArray or object of autocomplete values
autocompleteUniqueBooleantrueWhen true, only shows unique values in autocomplete list
autocompleteUrlStringnullURL to fetch autocomplete data
autocompleteUrlMethodString"GET"HTTP method for autocomplete URL request
autocompleteUrlKeyStringnullKey to extract data from JSON response
autocompleteDividerString","Divider for autocomplete values
autocompleteListHeightNumber200Maximum height of autocomplete list in pixels
labelString""Label text for the input
sizeString"normal"Size of the input: “small”, “normal”, or “large”
tagInputDeferredNumber0Delay before initialization (milliseconds)
staticBooleanfalseWhen true, makes the component read-only
clearButtonBooleantrueWhen true, shows a clear button
clearButtonIconString"❌"Icon for the clear button
randomColorBooleanfalseWhen true, assigns random colors to tags
maxTagsNumber0Maximum number of tags (0 for unlimited)
tagSeparatorString","Character used to separate tags in the value
tagTriggerString"Enter, Space, Comma"Keys that trigger tag creation
backspaceBooleantrueWhen true, allows removing last tag with backspace
clsComponentString""Additional CSS class for the component
clsInputString""Additional CSS class for the input
clsClearButtonString""Additional CSS class for the clear button
clsTagString""Additional CSS class for tags
clsTagTitleString""Additional CSS class for tag titles
clsTagActionString""Additional CSS class for tag action buttons
clsLabelString""Additional CSS class for the label
EventDescription
onBeforeTagAddTriggered before a tag is added. Return false to prevent adding
onTagAddTriggered when a tag is added
onBeforeTagRemoveTriggered before a tag is removed. Return false to prevent removing
onTagRemoveTriggered when a tag is removed
onTagTriggered when a tag is added or removed
onClearTriggered when all tags are cleared
onTagTriggerTriggered when a tag trigger key is pressed
onTagInputCreateTriggered when the component is created

Returns an array of the current tags.

const tagInput = Metro.getPlugin('#my-tag-input', 'tag-input');
const tags = tagInput.tags();

Gets or sets the value of the tag input.

Parameters:

  • v (optional) - String or array of tags to set
// Get current tags
const tags = tagInput.val();
// Set new tags
tagInput.val("tag1, tag2, tag3");
// or
tagInput.val(["tag1", "tag2", "tag3"]);

Appends new tags to the existing ones.

Parameters:

  • v - String or array of tags to append
tagInput.append("tag4, tag5");
// or
tagInput.append(["tag4", "tag5"]);

Removes all tags.

tagInput.clear();

Disables the tag input.

tagInput.disable();

Enables the tag input.

tagInput.enable();

Toggles between enabled and disabled states.

tagInput.toggleState();

Toggles between static and editable modes.

Parameters:

  • val (optional) - Boolean to set static mode
// Toggle static mode
tagInput.toggleStatic();
// Set specific static mode
tagInput.toggleStatic(true); // Enable static mode
tagInput.toggleStatic(false); // Disable static mode

Sets the autocomplete list.

Parameters:

  • l - String or array/object of autocomplete values
tagInput.setAutocompleteList("value1, value2, value3");
// or
tagInput.setAutocompleteList(["value1", "value2", "value3"]);
VariableDefault ValueDescription
--taginput-border-radius4pxControls the border radius of the tag input
--taginput-colorvar(--input-color)Controls the text color of the tag input
VariableDefault ValueDescription
--tag-background#f8f8f8Background color for tags
--tag-color#191919Text color for tags
--tag-action-background#dcdcdcBackground color for tag action buttons
--tag-action-color#191919Text color for tag action buttons
.tag-input {
--taginput-border-radius: 8px;
--taginput-color: #0066cc;
}
.tag {
--tag-background: #e6f2ff;
--tag-color: #0066cc;
--tag-action-background: #0066cc;
--tag-action-color: #ffffff;
}
  • .tag-input - The main container class
  • .original-input - The original input element
  • .input-wrapper - The visible input field
  • .input-clear-button - The clear button
  • .padding-for-clear - Applied when clear button is present
  • .static-mode - Applied when the component is in static mode
  • .autocomplete-list - Autocomplete dropdown
  • .item - Autocomplete item
  • .tag - Individual tag elements
  • .title - Tag text
  • .action - Tag remove button
  • .small - Small tag size
  • .large - Large tag size
  • .static - Applied to non-removable tags
  • Accent colors: .primary, .secondary, .tertiary, etc.
  • Soft colors: .soft-red, .soft-green, .soft-blue, etc.
  • Normal colors: .normal-red, .normal-green, .normal-blue, etc.