Tag Input
A text field that turns each entry into a removable chip, with optional suggestions as you type.
<arc-tag-input>Overview
TagInput collects a list of free-text values as removable chips. Pressing Enter or typing the delimiter (a comma by default) adds the trimmed text as a tag, and pasted text is split on the delimiter into several tags at once.
Give it a suggestions array and matching values appear in a dropdown as the reader types. Free text is still accepted unless you set no-custom (allowCustom = false), and then only suggestions can be added. A duplicate isn't added, and the existing chip shakes to show why. The shake is off under reduced motion.
TagInput is form-associated and submits one FormData entry per tag under its name, so the server gets a repeated field. Once max-tags is reached, entry is disabled and a "-- max reached" hint appears.
Guidelines
Do
- Set a `label`. It renders as a `<label>` for the text input, so screen readers announce it
- Provide `suggestions` when there's a known vocabulary, to speed up entry and cut typos
- Set `allowCustom` to false when values must come from that vocabulary
- Set `max-tags` when the system receiving the values accepts only so many
- Listen to `arc-input` to fetch suggestions from a server as the reader types
Don't
- Don't use TagInput when readers pick from a fixed list and want to browse it. Use MultiSelect
- Don't pick a delimiter that can appear inside a value
- Don't use very long tag values. They overflow the chips
- Don't rely on the shake alone to explain a rejected value where it matters. Set an `error` message too
Features
- Keyboard: Backspace in an empty input removes the last tag, ArrowLeft from the start of the input moves into the chips, the arrows move between chips, Backspace or Delete removes one, and Escape returns to the input
- In the suggestion list, ArrowUp and ArrowDown move and Enter or a click adds the value
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-tag-input
label="Topics"
placeholder="Add a topic..."
suggestions='["JavaScript","TypeScript","Python"]'
max-tags="5"
></arc-tag-input>import { TagInput } from '@arclux/arc-ui-react';
export default function Example() {
return (
<TagInput
label="Topics"
placeholder="Add a topic..."
suggestions={['JavaScript', 'TypeScript', 'Python']}
maxTags={5}
onArcChange={(e) => console.log(e.detail.value)}
/>
);
}<script setup>
import { TagInput } from '@arclux/arc-ui-vue';
</script>
<template>
<TagInput
label="Topics"
placeholder="Add a topic..."
:suggestions="['JavaScript', 'TypeScript', 'Python']"
:maxTags="5"
/>
</template><script>
import { TagInput } from '@arclux/arc-ui-svelte';
</script>
<TagInput
label="Topics"
placeholder="Add a topic..."
suggestions={['JavaScript', 'TypeScript', 'Python']}
maxTags={5}
/>import { Component } from '@angular/core';
import { TagInput } from '@arclux/arc-ui-angular';
@Component({
imports: [TagInput],
template: `
<arc-tag-input
label="Topics"
placeholder="Add a topic..."
[suggestions]="['JavaScript', 'TypeScript', 'Python']"
[maxTags]="5"
/>
`,
})
export class MyComponent {}import { TagInput } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<TagInput
label="Topics"
placeholder="Add a topic..."
suggestions={['JavaScript', 'TypeScript', 'Python']}
maxTags={5}
/>
);
}import { TagInput } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<TagInput
label="Topics"
placeholder="Add a topic..."
suggestions={['JavaScript', 'TypeScript', 'Python']}
maxTags={5}
/>
);
}API
delimiterstring','- Character that commits the current text as a tag when typed; pasted text is split on it.
labelstring''- Visible label rendered above the field in a small uppercase style.
placeholderstring''- Hint text shown inside the field when no tags exist and the input is empty.
namestring''- Form field name. Each tag is submitted as its own FormData entry under this name.
disabledbooleanfalse- Disables the control, preventing interaction and reducing opacity to 50%.
errorstring''- Error message shown below the field; also applies error styling to the border.
valuestring[][]- Array of current tags. Updated on add/remove and emitted via
arc-change. suggestionsstring[][]- Autocomplete candidates. When non-empty, typing filters them into a dropdown listbox.
maxTagsnumber0- Maximum number of tags (0 = unlimited). At the limit, entry is disabled with a "-- max reached" hint.
allowCustombooleantrue- When false, only values from
suggestionscan be added; free text is rejected. readonlybooleanfalse- Prevents adding or removing tags while the field stays focusable and the tags still submit with the form.
size'sm' | 'md' | 'lg''md'- Control size.
mdis the default;smandlgscale the field height and padding. formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-changedetail:{ value: string[] }- Fired when a tag is added or removed; detail contains
{ value } arc-input- Fired as the user types; detail contains
{ query }
See also
- Multi SelectA dropdown for picking several options, shown as removable chips.
- ComboboxA text input that filters a list of options as you type, for picking one value from a long list.
- InputText field with a built-in label, placeholder and validation states. Set `multiline` for a textarea.
- TagA small uppercase pill for a category or filter, with an optional button to remove it.