Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

InputTags

InputTags groups a collection of contents in items.

React
JavaScript
Vue
Angular
preview

Usage#

import { InputTags } from '@primereact/ui/inputtags';
<InputTags.Root>
    <InputTags.Items>
        <InputTags.Item>
            <InputTags.Label />
            <InputTags.Remove />
        </InputTags.Item>
    </InputTags.Items>
    <InputTags.Input />
</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

No Duplicate#

By default, duplicate values are not allowed. Attempting to add an existing tag value will be ignored.

a
A
no-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#

The InputTags.Root component accepts a render function that provides access to the component instance, allowing full customization of tags, input field, and additional UI elements. The remove actions can be implemented with onItemRemoveClick and onRemoveAllItems, or components can be wrapped with additional functionality.

JavaScriptTypeScript
item-demo

Typeahead#

InputTags can be combined with typeahead functionality to provide suggestions as users type. Define an options array along with optionLabel to specify the display field. For grouped suggestions, use optionGroupLabel and optionGroupChildren properties. The onComplete callback is triggered on input change, enabling dynamic filtering and updating of suggestions.

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.

events-demo

Float Label#

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

float-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

API#

Sub-Components#

See Primitive API for InputTagsRoot, InputTagsItems, InputTagsItem, InputTagsInput, and other component documentation.

Hooks#

See Headless API for useInputTags hook documentation.

Accessibility#

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