3.20.3 • Published 1 year ago

react-tagsinput v3.20.3

Weekly downloads
61,027
License
MIT
Repository
github
Last release
1 year ago

react-tagsinput

NPM version Size Code coverage Download count js-standard-style

Highly customizable React component for inputing tags.

Demo

Example

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

import 'react-tagsinput/react-tagsinput.css'

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

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

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

Table of Contents

Styling

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

Component Interface

Props

value (required)

An array of tags.

onChange (required)

Callback when tags change, gets three arguments tags which is the new tag array, changed which is an array of the tags that have changed and changedIndexes which is an array of the indexes that have changed.

onChangeInput

Callback from the input box, gets one argument value which is the content of the input box. (onChangeInput is only called if the input box is controlled, for this to happen both inputValue and onChangeInput need to be set)

addKeys

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

currentValue

A string to set a value on the input.

inputValue

Similar to currentValue but needed for controlling the input box. (inputValue is only useful if you use it together with onChangeInput)

onlyUnique

Allow only unique tags, default is false.

validate

Allow only tags that pass this validation function. Gets one argument tag which is the tag to validate. Default is () => true.

validationRegex

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

onValidationReject

Callback when tags are rejected through validationRegex, passing array of tags as the argument.

disabled

Passes the disabled prop to renderInput and renderTag, by default this will "disable" the component.

maxTags

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

addOnBlur

Add a tag if input blurs. Default false.

addOnPaste

Add a tags if HTML5 paste on input. Default false.

pasteSplit

Function that splits pasted text. Default is:

function defaultPasteSplit (data) {
  return data.split(' ').map(d => d.trim())
}
removeKeys

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

className

Specify the wrapper className. Default is react-tagsinput.

focusedClassName

Specify the class to add to the wrapper when the component is focused. Default is react-tagsinput--focused.

tagProps

Props passed down to every tag component. Default is:

{
  className: 'react-tagsinput-tag',
  classNameRemove: 'react-tagsinput-remove'
}
inputProps

Props passed down to input. Default is:

{
  className: 'react-tagsinput-input',
  placeholder: 'Add a tag'
}
tagDisplayProp

The tags' property to be used when displaying/adding one. Default is: null which causes the tags to be an array of strings.

renderTag

Render function for every tag. Default is:

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

Render function for input. Default is:

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

Note: renderInput also receives addTag as a prop.

renderLayout

Renders the layout of the component. Takes tagElements and inputElement as args. Default is:

function defaultRenderLayout (tagElements, inputElement) {
  return (
    <span>
      {tagElements}
      {inputElement}
    </span>
  )
}
preventSubmit

A boolean to prevent the default submit event when adding an 'empty' tag. Default: true

Set to false if you want the default submit to fire when pressing enter again after adding a tag.

Methods

focus()

Focus on input element.

blur()

Blur input element.

accept()

Try to add whatever value is currently in input element.

addTag(tag)

Convenience method that adds a tag.

clearInput()

Clears the input value.

Contributors

Changelog

License


MIT Licensed

oss-tools-frontendecp-frontendmulti-billingmulti-checkoutsubill-pricingsubillcheckoutcheckout-subillbilling-subill@everything-registry/sub-chunk-2617bpm-componentstest-framework-shreyasxcim-codesandboxxl-react-componentswso2_apim_publisherservicebotservicebot-billing-settings-embedservicebot-checkout-embedreactjs-event-managementsuper-duper-rendererstorybuilder-reactswp-ui-kitveem-web-sdkliangzhi-tagsinputlinqstream-moduleslingssoft-lingssiteiamrobksawyerkuky-cmskuky-dashboardglenns-meathandling-dashboardmoor-adminlsf-reactpalace-botoptimizely-ouipipesort-admin-templatens1-guiodfsharedolive-pathwayprestein-danteprisma-adminpec-reactpcmli.umbrella.web-uireact-genericreact-gentelellareact-dynamic-form-creationreact-simpl-formreact-simpl-form-fieldsrahul-components-afrozreact-graph-db-editorstrapi-plugin-tagsinputsurvey-bot-feslonsimple-react-form-bootstrapuhs-kit@ahaui/react@alphalets-ui/core@bcrumbs.net/bc-ui@bigfishtv/cockpit@bufferapp/posts-table@bufferapp/campaign-posts-table111-react-simpleform@codesandbox/components@codementor/ui-kit@coinjoss-ui/core@deskpro/react-componentswao-react-shared-componentszjs-react-video@ebilling/servicebot-billing-settings-embed@ebilling/servicebot-checkout-embed@front10/component-explorer-utils@gotitinc/aha-react@eventgenius/ui-lib@leveluptuts/fresh@mynewsdesk/ui@erick-otenyo/hw-components@eservices/servicebot@eservices/servicebot-billing-settings-embed@eservices/servicebot-checkout-embed@mip-studio/components@intellyo/intellyo-components@jkol36/design-system-deprecated@odf-console/shared@samhenderson511/strapi-plugin-tagsinput@parkassist/pa-elements@softwarebybaas/blog-ms-frontend@robostack/zethus@siteone/media-library@descco/uialfonsomthd-odftest@zalastax/nolb-react-taadmin-portal@worldresources/gfw-components@weenspace/react-core@weenspace/react-materialcheckout-srccezerinchainofdemandcore-frontdeskpro-componentsdicol-dashboardebilling-billing-settings-embed
3.20.2

1 year ago

3.20.3

1 year ago

3.20.1

2 years ago

3.20.0

2 years ago

3.19.0

7 years ago

3.18.0

7 years ago

3.17.0

7 years ago

3.16.1

8 years ago

3.16.0

8 years ago

3.15.1

8 years ago

3.15.0

8 years ago

3.14.3

8 years ago

3.14.2

8 years ago

3.14.1

8 years ago

3.14.0

8 years ago

3.13.6

8 years ago

3.13.5

8 years ago

3.13.4

8 years ago

3.13.3

8 years ago

3.13.2

8 years ago

3.13.1

8 years ago

3.13.0

8 years ago

3.12.0

8 years ago

3.11.0

8 years ago

3.10.0

8 years ago

3.9.1

8 years ago

3.9.0

8 years ago

3.8.2

8 years ago

3.8.1

8 years ago

3.8.0

8 years ago

3.7.3

8 years ago

3.7.2

8 years ago

3.7.1

8 years ago

3.7.0

9 years ago

3.6.2

9 years ago

3.6.1

9 years ago

3.6.0

9 years ago

3.5.1

9 years ago

3.5.0

9 years ago

3.4.1

9 years ago

3.4.0

9 years ago

3.3.0

9 years ago

3.2.1

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.5.0

9 years ago

1.4.7

9 years ago

1.4.6

9 years ago

1.4.5

9 years ago

1.4.4

9 years ago

1.5.0-beta1

9 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.9

9 years ago

1.3.8

9 years ago

1.3.7

9 years ago

1.3.6

9 years ago

1.3.5

9 years ago

1.3.4

9 years ago

1.3.3

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.2

10 years ago