1.0.6 • Published 5 years ago

@sentisis/react-tags-input v1.0.6

Weekly downloads
29
License
MIT
Repository
github
Last release
5 years ago

React-Tags-Input

An input control that handles tags interaction with copy-paste and custom type support.

demo

Live Playground

For examples of the tags input in action, check the demo page

Installation

The easiest way to use it is by installing it from NPM and include it in your own React build process.

npm install @sentisis/react-tags-input --save

Usage

Example usage:

import React from 'react';
import TagsInput from '@sentisis/react-tags-input';
// Either a copy of our demo CSS or your custom one
import './TagsInput.css';

export default class Demo extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      tags: [],
    };
  }

  render() {
    return (
      <TagsInput
        label="Tags"
        placeholder="Write tags"
        tags={this.state.tags}
        onChange={tags => this.setState({ tags })}
      />
    );
  }
}

API

Currently the component listen to the following keys: enter, esc, backspace, mod+a, mod+c and mod+v (for copy/paste).

It supports a keyboard-only copy paste (using mod+a).

copy-paste-demo

Each tag you will be passing should have the following shape:

PropertyTypeRequiredDescription
valueStringtrueTag value
specialBooleanfalseSpecial marks the tag as different. For example a special tag when using the case-sensitive options is a case-sensitive tag

The TagsInput component contains the following properties:

PropertyTypeDefaultDescription
tagsArray<Tags>[]Array of tags to display
labelStringundefinedRendered above the field itself
placeholderStringundefinedInput placeholder
errorStringundefinedError message rendered below the field. When the field is set it will also have the class is-error
tagRendererFunctionundefinedOptional function that gets used to render the tag
copyButtonBooleanfalseRenders a copy to clipboard button
copyButtonLabelStringCopy to clipboardLabel for the copy to clipboard button
blacklistCharsArray<String>','Characters not allowed in the tags. Must always contain ,
specialTagsBooleanfalseEnable the creation of special tags
specialButtonRendererFunctionundefinedFunction that gets used to render the special button
specialButtonLabelStringSpecialLabel for the special button. Only used when a specialButtonRenderer is not defined
onChangeFunctionnoopFired when changing the tags with the tags array as the argument
onBlurFunctionnoopFired as the standard React SyntheticEvent
onFocusFunctionnoopFired as the standard React SyntheticEvent
onSubmitFunctionnoopFired when the user interaction is considered complete, invoked with tags