Giter Site home page Giter Site logo

react-tagsinput's Introduction

react-tagsinput

NPM version Build Status Coverage Status Dependency Status Download Count js-standard-style

Simple React component for inputing tags.

Demo

Install

npm install react-tagsinput --save

or

bower install react-tagsinput --save

Example

import TagsInput from 'react-tagsinput'

class TestComponent extends React.Component {
  constructor() {
    super()
    this.state = {tags: []}
  }

  handleChange(tags) {
    this.setState({tags})
  }

  render() {
    return <TagsInput value={this.state.tags} onChange={::this.handleChange} />
  }
}

Interface

Props

value (required)

An array of tags.

onChange (required)

Callback when tags change.

addKeys

An array of key codes that add a tag, default is [9, 13] (Tab and Enter).

onlyUnique

Allow only unique tags, default is false.

validationRegex

Allow only tags that pass this regex to be added. Default is /.*/.

maxTags

Allow limit number of tags, default is -1 for infinite.

addOnBlur

Add a tag if input blurs.

removeKeys

An array of key codes that remove a tag, default is [8] (Backspace).

tagProps

Props passed down to every tag component. Defualt is: {className: 'react-tagsinput-tag', classNameRemove: 'react-tagsinput-remove'}.

inputProps

Props passed down to input. Default is: {className: 'react-tagsinput-input'}

renderTag

Render function for every tag. Default is:

function defaultRenderTag (props) {
  let {tag, key, onRemove, ...other} = props
  return (
    <span key={key} {...other}>
      {tag}
      <a onClick={(e) => onRemove(key)} />
    </span>
  )
}
renderInput

Render function for input. Default is:

function defaultRenderInput (props) {
  let {onChange, value, ...other} = props
  return (
    <input type='text' onChange={onChange} value={value} {...other} />
  )
}
renderLayout

Renders the layout of the component. Takes tagComponents and inputComponent as args. Default is:

function defaultRenderLayout (tagComponents, inputComponent) {
  return (
    <span>
      {tagComponents}
      {inputComponent}
    </span>
  )
}

Styling

Look at react-tagsinput.css for a basic style.

Contributors

  • Ola Holmström (@olahol)
  • Dmitri Voronianski (@voronianski)
  • Artem Vovsya (@avovsya)
  • scott c (@scoarescoare)
  • junk (@jedverity)
  • Buz Carter (@buzcarter)
  • Garbin Huang (@garbin)
  • Will Washburn (@willwashburn)
  • Kristján Oddsson (@koddsson)
  • Vojtěch Bartoš (@VojtechBartos)
  • Ming Fang (@mingfang)
  • Chris Adams (@thecadams)
  • Domenico Matteo (@dmatteo)
  • Kevin Smith (@ksmth)
  • Gaurav Tiwari (@gauravtiwari)
  • Tay Yang Shun (@yangshun)
  • Trevor Hutto (@huttotw)
  • David L. Goldberg (@DavidLGoldberg)
  • Pedro J. Parra (@pedroparra)
  • Kasper Kasper Nilsson (@k-nilsson)

MIT Licensed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.