react-tagging-input
Simple tagging component.
Demo
https://jfusco.github.io/react-tagging-input
Getting Started
Installation
From the root of your project.
npm install react-tagging-input --save
Usage
Simple implementation of tags. See options available below.
;;; state = tags: 'foo' 'bar' ; { superprops; } { this; } { this; } { return <div> <Tags tags=thisstatetags placeholder="Add a tag" onAdded=thisonTagAdded onRemoved=thisonTagRemoved /> </div> ; } ;
Options
tags ~ required
An array
of tags to be passed in and rendered right away in the component
state = tags: 'foo' 'bar'; <Tags tags=thisstatetags />
null
placeholder ~ optional ~ default A string
used as placeholder text in the tags input field
<Tags placeholder="Add a tag" />
[13, 9, 32]
addKeys ~ optional ~ default An array
of keyCodes used to tell the tags component which delimiter to use to add a tag
Here is more info and a list of keyCodes
<Tags addKeys=13 9 32 188 />
onAdded ~ optional
A function
fired when a new tag is added - returns a string
of the new tag
{ console;} <Tags onAdded=thisonTagAdded />
onRemoved ~ optional
A function
fired when a new tag is deleted - returns a string
of the tag that was deleted
{ console;} <Tags onRemoved=thisonTagRemoved />
-1
(infinite)
maxTags ~ optional ~ default An integer
representing the maximum number of tags that are allowed to be added
<Tags maxTags=10 />
false
readOnly ~ optional ~ default A boolean
that sets the tag component to read only mode. No adding or removing tags and pointer events
<Tags readOnly=true />
"x"
removeTagIcon ~ optional ~ default The element
to be used for the delete icon
const removeIcon = { return <i class="my-custom-icon"></i> ;} <Tags removeTagsIcon= />
false
uniqueTags ~ optional ~ default A boolean
that allows the same tag to be added more than once
//-- Only allow unique tags to be added<Tags uniqueTags=true />
null
id ~ optional ~ default The string
to be used for the ID of the component
<Tags id="my-tags-component" />
Styling
Installation
Import the main SCSS file in to your application SCSS files
;
There are a few variables set to !default
that can be overriden. If you need to change it more just override the actual styles.
Any overriden variables needs to go above the @import
statement to take effect
//-- Global UI $tag-base-height $tag-base-font-size $tag-base-border-radius $tag-base-font-color $tag-base-margin $tag-base-font-family //-- Tags $tag-background-color $tag-background-hover-color $tag-remove-color $tag-remove-font-size $tag-remove-hover-color //-- Input $tag-input-bg-color $tag-input-border $tag-input-placeholder-color
If you don't care to override variables and just want to override actual styles you may choose to import the compiled version of the css instead
;
Tests
npm test