React Tags Input Component

3.20.3 · active · verified Sun Apr 19

`react-tagsinput` is a highly customizable React component designed for creating user interfaces that allow users to input and manage tags. It is currently at version 3.20.3, indicating a mature and stable codebase. While an explicit release cadence isn't regularly published, the package appears to be in a maintenance phase, receiving updates primarily for compatibility and bug fixes rather than frequent feature additions. Its key differentiators include extensive customization options through `renderTag`, `renderInput`, and `renderLayout` props, enabling developers to fully control the visual representation of tags and the input field. It supports various methods for adding tags, such as pressing `Enter` or `Tab`, blurring the input field, and pasting text, along with options for validation and enforcing unique tags. The component is agnostic to styling, requiring developers to provide their own CSS (or import the provided basic stylesheet) to match their application's design system.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `react-tagsinput` with functional components, state management using `useState`, and essential styling.

import React from 'react';
import TagsInput from 'react-tagsinput';

import 'react-tagsinput/react-tagsinput.css'; // Don't forget to import the styles!

function App() {
  const [tags, setTags] = React.useState(['react', 'javascript']);

  const handleChange = (newTags) => {
    setTags(newTags);
  };

  return (
    <div>
      <h1>My Tag Editor</h1>
      <p>Add some tags related to your project:</p>
      <TagsInput
        value={tags}
        onChange={handleChange}
        maxTags={10}
        addOnBlur={true}
        onlyUnique={true}
        inputProps={{ placeholder: 'Add a new tag' }}
        tagProps={{
          className: 'react-tagsinput-tag',
          classNameRemove: 'react-tagsinput-remove'
        }}
      />
      <p>Current tags: {tags.join(', ')}</p>
    </div>
  );
}

view raw JSON →