# InputTags An unstyled tag input component with keyboard navigation, delimiter support, and optional typeahead suggestions. ## Features - Tag creation on Enter key press with optional delimiter character - Maximum tag limit with `max` prop - Duplicate prevention with `allowDuplicate` - Optional typeahead suggestions by composing `AutoComplete.Root` inside `InputTags.Control` - Add and remove event callbacks for fine-grained control - Paste support with `addOnPaste` and automatic delimiter splitting ## Usage ```tsx import { InputTags } from 'primereact/inputtags'; ``` ```tsx setTags(e.value)}> {({ item, remove }) => ( {item} )} {({ controlProps }) => } ``` `InputTags.Items` is a pure render-prop iterator: it invokes `children` once per tag with `{ item, index, remove, itemProps }`. Spread `itemProps` onto the rendered chip element to wire ARIA roles and the `data-selected` focus marker. `InputTags.Control` calls `children` exactly once with `{ controlProps, add, remove, removeLast, removeAll, value, inputValue, focused }`. `add` accepts either a single string or an array of strings. ### With Typeahead For suggestion-driven tag entry, mount an `` tree inside ``. Spread `controlProps` onto `` so the text-entry gets InputTags' Backspace-to-remove, delimiter-split, `addOnBlur` / `addOnPaste`, and focus handlers. On `AutoComplete.onValueChange` (option selection), call `add` from the render-prop arg to commit the tag. Attach a callback ref + state to `` and pass that element to `` so the suggestion popup sizes against the full chip-input field rather than just the typing area. ```tsx import { AutoComplete } from 'primereact/autocomplete'; import { InputTags } from 'primereact/inputtags'; const [rootEl, setRootEl] = React.useState(null); setTags(e.value)}> {({ item, remove, itemProps }) => ( {item} )} {({ controlProps, add }) => ( { if (typeof e.value === 'string') add(e.value); }} > No results found )} ; ``` ## Behavior ### Polymorphic Root Use `as` on `InputTags.Root` to change the rendered HTML element. ```tsx ... ``` ### Render Prop Architecture The component intentionally has no Item / Label / Remove / Input sub-parts. Consumers compose the per-tag JSX (e.g. `Chip.*`, `Tag`, custom) inside `InputTags.Items`, and the text-entry element (a plain ``, ``, or anything else) inside `InputTags.Control`. ## Pass Through ## API ### InputTagsRoot | Attribute | Value | | ------------ | ------------- | | `data-scope` | `"inputtags"` | | `data-part` | `"root"` | | Label | Type | Description | |:------|:------|:------| | root | InputTagsRootPassThroughType> | Used to pass attributes to the root's DOM element. | ### InputTagsItems `InputTagsItems` accepts a render-prop child invoked once per tag with `{ item, index, remove, itemProps }`. Spread `itemProps` onto the rendered chip element for ARIA + keyboard navigation between tags. ### InputTagsControl `InputTagsControl` accepts a render-prop child invoked once with `{ controlProps, add, remove, removeLast, removeAll, value, inputValue, focused }`. Spread `controlProps` onto a text-entry element (plain ``, ``, etc.). Call `add(tag)` or `add([tag1, tag2])` to commit one or more tags programmatically. When you need the root DOM node (for popup anchors, scroll-into-view, etc.), attach a callback ref via `ref={setRootEl}` on `` and use the tracked state. ## Accessibility ### Screen Reader The root container uses `role="listbox"` with `aria-orientation="horizontal"`. Each tag (via `itemProps`) has `role="option"` with `aria-selected`, `aria-setsize`, and `aria-posinset`. The text-entry element's ARIA depends on what the consumer renders: a plain `` is just a text field; an `` adds combobox + `aria-haspopup` / `aria-expanded` / `aria-controls` semantics automatically. ### Keyboard Support | Key | Function | | ------------- | ---------------------------------------------------- | | `tab` | Moves focus to the input element. | | `enter` | Adds a new tag with the current input value. | | `backspace` | Removes the last tag when input is empty. | | `left arrow` | Moves focus to the previous tag when input is empty. | | `right arrow` | Moves focus to the next tag when focused on a tag. | ### Tag Keyboard Support | Key | Function | | ----------- | ------------------------ | | `backspace` | Removes the focused tag. | | `delete` | Removes the focused tag. |