Inputs
TagInput
quarterly
finance
Press Enter or a comma to add a tag, Backspace to remove the last one
2 of 6 tags
When to use
- The user enters several arbitrary tags, including ones made of several words.
- You need each tag to be removable in an accessible way, and the
maxlimit.
When not to use
- If the set is predefined, use
Select multiple,CheckboxGrouporToggleGroup. - If you need only a single free-form text value, use
TextControlorCombobox.
Minimal example
<TagInput label="Tags" value={tags} onChange={setTags} placeholder="Enter a tag" max={8} />Public API
valueandonChangeare required; they are the only source of the set of tags.labeloraria-labelnames the group; the input automatically gets a separate name "…: add".maxdisables input when the limit is reached.disabledblocks the input;placeholderdisappears when the set is full.- A pasted string is split at commas; spaces inside tags are kept; adding on blur happens only when focus leaves the component entirely.
Accessibility and keyboard
- The hint and error of
FormFieldare announced together with the field. The description arrives through context, andaria-describedbyis set on the input, not on the group of tags; the value set by the consumer is not replaced but merged with it. Before version 3.0.0 the components built on react-aria did not pick up the form description — it was on the screen but did not reach the screen reader (ADR-0031). - Enter on an empty input deliberately does not submit the form.
- The remove button has a name that includes the specific tag; do not replace it with a custom button.
- See
src/components/inputs/TagInput.tsx,src/components/inputs/TagInput.stories.tsx,tests/tag-input.test.tsx.
TypeScript types
TagInputProps
Prop
Type