2.0.3 • Published 12 months ago

react-ts-tagsinput v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-ts-tagsinput

A simple and customizable React tags input component written in TypeScript.

Screenshot

Live Demo

Installation

Install the component using npm package manager:

npm i react-ts-tagsinput

Example

import React from "react";
import type { Tag } from 'react-ts-tagsinput';
import { TagsInput } from "react-ts-tagsinput";
// Import default styling (optional)
import 'react-ts-tagsinput/lib/defaultTheme.css';

export default function App() {

  const [tags, setTags] = React.useState<Array<Tag>>(["Tag 1", "Tag 2", "Tag 3", "Tag 4"]);

  const handleTagsChange = React.useCallback((updatedTags: Array<Tag>) => {
    setTags(updatedTags);
  }, []);
  
  return(
    <div className='app'>
      <TagsInput name="myTags" placeholder="Add a tag" value={tags} onChange={handleTagsChange} />
    </div>
  );
  
}

Documentation

Props

PropTypeDescriptionRequiredDefault
namestringThe name attribute of the input field.Yes-
typestringThe type of the input field.Notext
placeholderstringThe placeholder of the input field.NoAdd a tag
valueArray\The array of tags.Yes-
allowDuplicatesbooleanWhether to allow duplicate tags or not.Nofalse
disabledbooleanWhether the input field is disabled or not.Nofalse
prependstringText to prepend before each tag. Example: #.No-
maxnumberLimit the maximum number of tags. Set -1 for no limit.No-1
addOnBlurbooleanWhether to add the tag when the user presses tab on the input.Nofalse
autoFocusbooleanWhether to autofocus the inputfield on component mount.Nofalse
hideSubmitButtonbooleanWhether to hide the submit button.Nofalse
onChangeFunction(newTags: Array\) => voidThe callback function that is called whenever there is a change in the tags array.No-
inputPropsObject{key: string: unknown}Use this prop to add extra attributes to the input field.No-
tagPropsObject{key: string: unknown}Use this prop to add extra attributes to the 'tag' div.No-
formPropsObject{key: string: unknown}Use this prop to add extra attributes to the form.No-
tagValidationFunction(tag: Tag) => booleanThe validation function to run after each form submit. Return false to prevent adding the tag. You can add any type of validation including regex. Simply pass your validation function to this prop.No() => true
tagFilterFunction(tag: Tag) => TagThe filter function that lets you modify the tag just before it is added. For example, you can use this to remove all the whitespaces from the tag.No-

Changelog

https://github.com/nitishkgupta/react-ts-tagsinput/blob/master/CHANGELOG.md

Contributions

Open to feedback and contributions at nitishkgupta/react-ts-tagsinput.

2.0.3

12 months ago

2.0.2

12 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago