2.0.2 • Published 2 years ago

react-tag-input-component v2.0.2

Weekly downloads
47
License
MIT
Repository
github
Last release
2 years ago

react-tag-input-component

lightweight component for tag(s) input

GitHub Actions Status NPM gzip

also see multi select component

✨ Features

  • 🍃 Lightweight (2KB including styles 😎)
  • 💅 Themeable
  • ✌ Written w/ TypeScript
  • 🗑️ Use Backspace to remove last tag

🔧 Installation

npm i react-tag-input-component    # npm
yarn add react-tag-input-component # yarn

📦 Example

Example

Edit react-tag-input-component

import React, { useState } from "react";
import { TagsInput } from "react-tag-input-component";

const Example = () => {
  const [selected, setSelected] = useState(["papaya"]);

  return (
    <div>
      <h1>Add Fruits</h1>
      <pre>{JSON.stringify(selected)}</pre>
      <TagsInput
        value={selected}
        onChange={setSelected}
        name="fruits"
        placeHolder="enter fruits"
      />
      <em>press enter or comma to add new tag</em>
    </div>
  );
};

export default Example;

👀 Props

PropDescriptionTypeDefault
namevalue for name of inputstring
placeholderplaceholder for text inputstring
valueinitial tagsstring[][]
onChangeonChange callback (added/removed)string[]
classNamesclassName for styling input and tags (i.e {tag:'tag-cls', input: 'input-cls'})object[tag, input]
onKeyUpinput onKeyUp callbackevent
onBlurinput onBlur callbackevent
separatorswhen to add tag (i.e. "Enter", " ")string[]["Enter"]
removersRemove last tag if textbox empty and Backspace is pressedstring[]["Backspace"]
onExistingif tag is already added then callback(tag: string) => void
onRemovedon tag removed callback(tag: string) => void
beforeAddValidateCustom validation before adding tag(tag: string, existingTags: string[]) => boolean
isEditOnRemoveRemove the tag but keep the word in the input to edit it on using Backscape Keybooleanfalse

💅 Themeing

You can override CSS variables to customize the appearance

.rti--container {
  --rti-bg: "#fff",
  --rti-border: "#ccc",
  --rti-main: "#3182ce",
  --rti-radius: "0.375rem",
  --rti-s: "0.5rem", /* spacing */
  --rti-tag: "#edf2f7",
  --rti-tag-remove: "#e53e3e",
}

use !important if CSS variables are not getting applied

🤠 Credits

📜 License

MIT © harshzalavadiya

2.0.2

2 years ago

2.0.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

2.0.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

3 years ago