1.0.6 • Published 5 years ago

@kilfro/tags-input v1.0.6

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

@kilfro/tags-input

Build Status NPM

This is a simple react component for inputting tags.

demo

Install

npm install --save @kilfro/tags-input

Usage

import React, { useState } from 'react'
import TagsInput from '@kilfro/tags-input'

const Example = () => {
  const [tags, setTags] = useState([])

  return(
    <TagsInput values={tags} onChange={setTags} />
  )
}

Props

NameTypeDefaultDescription
valuesarrayList of values
onChangefunctionCallback function to change values
TagItemWrappercomponentCustom wrapper for tags. More info
placeholderstringPlaceholder for input field
autoPastedbooleanfalseAutomatically splitting pasted string to tags by splitter. More info
splitterstring' 'String for autosplit long string to tags
inputStyleobjectInline styles for input field
inputClassNamestringClass names for input field
tagsPosition'top' \| 'bottom''bottom'Use to change position of tags list

Custom tag wrapper

You can use prop TagItemWrapper to change tag item wrapper. Your custom component has to implement two props:

  • children as tag values;
  • removeHandler as callback function to remove tag.

Example:

import React, { useState } from 'react'
import TagsInput from '@kilfro/tags-input'

const MyWrapper = ({ children, removeHandler }) => {
    const style = {
        margin: 5,
        backgroundColor: 'gray',
        fontWeight: 'bold',
        color: 'white',
    }

    return (
        <button style={style} onClick={removeHandler}>{children}</button>
    )
}

const Example = () => {
  const [tags, setTags] = useState([])

  return(
    <TagsInput 
      values={tags} 
      onChange={setTags} 
      TagItemWrapper={MyWrapper}
    />
  )
}

Pasting from the clipboard

If prop autoPasted is true, input will split pasted string and add new values automatically. You can also change splitter (by default this is space) using prop splitter.

Key events

Tag input handles some key events:

  • Enter - add typed value;
  • Esc - clear input;
  • ArrowUp - change typed value to upper case;
  • ArrowDown - change typed value to lowwer case.

License

MIT © Kirill Frolov

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago