Next Chapter Begins 🚀Read the full story
styledForm

InputTags

InputTags groups a collection of contents in items.

React
JavaScript
preview

Usage#

import { InputTags } from '@primereact/ui/inputtags';
import { InputText } from '@primereact/ui/inputtext';
import { Chip } from '@primereact/ui/chip';

InputTags.Items takes a render-prop child invoked per tag with { item, index, remove, itemProps }. Spread itemProps onto the rendered chip for ARIA roles and the data-selected focus marker. InputTags.Control exposes the text-entry props plus tag-mutation helpers, spread controlProps onto any input element.

<InputTags.Root value={tags} onValueChange={(e) => setTags(e.value)}>
    <InputTags.Items>
        {({ item, remove, itemProps }) => (
            <Chip.Root {...itemProps}>
                <Chip.Label>{item}</Chip.Label>
                <Chip.Remove onClick={remove}>×</Chip.Remove>
            </Chip.Root>
        )}
    </InputTags.Items>
    <InputTags.Control>{({ controlProps }) => <InputText {...controlProps} />}</InputTags.Control>
</InputTags.Root>

For typeahead support, render an <AutoComplete.Root> tree inside <InputTags.Control> and call add from the autocomplete's onValueChange. add accepts either a single string or an array of strings. Track the InputTags root element via a callback ref + state and pass it to <AutoComplete.Positioner anchor={...}> so the popup matches the full field width instead of just the input.

const [rootEl, setRootEl] = React.useState<HTMLElement | null>(null);
 
<InputTags.Root ref={setRootEl} value={skills} onValueChange={(e) => setSkills(e.value)}>
    <InputTags.Items>
        {({ item, remove, itemProps }) => (
            <Chip.Root {...itemProps}>
                <Chip.Label>{item}</Chip.Label>
                <Chip.Remove onClick={remove}>×</Chip.Remove>
            </Chip.Root>
        )}
    </InputTags.Items>
    <InputTags.Control>
        {({ controlProps, add }) => (
            <AutoComplete.Root
                options={items}
                optionLabel="label"
                onComplete={onSearch}
                onValueChange={(e) => {
                    if (e.option) add(e.option.label);
                }}
            >
                <AutoComplete.Input {...controlProps} />
                <AutoComplete.Portal>
                    <AutoComplete.Positioner anchor={rootEl}>
                        <AutoComplete.Popup>
                            <AutoComplete.List />
                        </AutoComplete.Popup>
                    </AutoComplete.Positioner>
                </AutoComplete.Portal>
            </AutoComplete.Root>
        )}
    </InputTags.Control>
</InputTags.Root>;

Examples#

Basic#

Allows entering multiple values as removable tags.

React
basic-demo

Delimiter#

A new tag is added when enter key is pressed, delimiter property allows defining an additional key. Currently only valid value is , to create a new item when comma key is pressed.

delimiter-demo

Allow Duplicate#

When allowDuplicate is enabled, the same value can be added multiple times as separate tags.

a
A
a
allow-duplicate-demo

Max#

The max property limits the number of tags that can be added. Once the limit is reached, no more tags can be entered.

React
max-demo

Item#

InputTags.Items takes a render-prop child invoked per tag with { item, index, remove, itemProps }. Compose any chip-like JSX inside, Chip.*, Tag, a plain <span>, etc.

JavaScriptTypeScript
item-demo

Typeahead#

InputTags composes with AutoComplete for typeahead-driven tag entry. Render <AutoComplete.Root> inside <InputTags.Control>, spread controlProps onto <AutoComplete.Input>, and call add(label) from AC's onValueChange when an option is selected. AC's onComplete drives filtering; grouped suggestions work via optionGroupLabel / optionGroupChildren on AC.

typeahead-demo

Events#

The onAdd and onRemove callbacks are triggered when tags are added or removed, providing the tag value and index for custom handling like logging, analytics or validation.

// no events yet
events-demo

Float Label#

A floating label is displayed when the input is focused or filled.

float-label-demo

Ifta Label#

IftaLabel is used to create infield top aligned labels. Visit IftaLabel documentation for more information.

ifta-label-demo

Filled#

Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.

React
filled-demo

Invalid#

Invalid state is displayed using the invalid prop to indicate a failed validation. This style is useful when integrating with form validation libraries.

invalid-demo

Disabled#

When disabled is present, the element cannot be edited and focused.

React
disabled-demo

Sub-Components#

See Primitive API for InputTagsRoot, InputTagsItems, and InputTagsControl documentation.

Hooks#

See Headless API for useInputTags hook documentation.

Accessibility#

See InputTags Primitive for WAI-ARIA compliance details and keyboard support.