1- import React from 'react'
1+ import React , { Component , PropTypes } from 'react'
22
33function defaultRenderTag ( props ) {
44 let { tag, key, onRemove, classNameRemove, ...other } = props
@@ -11,10 +11,10 @@ function defaultRenderTag (props) {
1111}
1212
1313defaultRenderTag . propTypes = {
14- key : React . PropTypes . number ,
15- tag : React . PropTypes . string ,
16- onRemove : React . PropTypes . function ,
17- classNameRemove : React . PropTypes . string
14+ key : PropTypes . number ,
15+ tag : PropTypes . string ,
16+ onRemove : PropTypes . function ,
17+ classNameRemove : PropTypes . string
1818}
1919
2020function defaultRenderInput ( props ) {
@@ -25,8 +25,8 @@ function defaultRenderInput (props) {
2525}
2626
2727defaultRenderInput . propTypes = {
28- value : React . PropTypes . string ,
29- onChange : React . PropTypes . function
28+ value : PropTypes . string ,
29+ onChange : PropTypes . function
3030}
3131
3232function defaultRenderLayout ( tagComponents , inputComponent ) {
@@ -38,42 +38,14 @@ function defaultRenderLayout (tagComponents, inputComponent) {
3838 )
3939}
4040
41- class TagsInput extends React . Component {
41+ class TagsInput extends Component {
4242 constructor ( ) {
4343 super ( )
4444 this . state = { tag : '' }
4545 this . focus = ::this . focus
4646 this . blur = ::this . blur
4747 }
4848
49- static propTypes = {
50- addKeys : React . PropTypes . array ,
51- addOnBlur : React . PropTypes . bool ,
52- inputProps : React . PropTypes . object ,
53- onChange : React . PropTypes . func . isRequired ,
54- removeKeys : React . PropTypes . array ,
55- renderInput : React . PropTypes . func ,
56- renderTag : React . PropTypes . func ,
57- renderLayout : React . PropTypes . func ,
58- tagProps : React . PropTypes . object ,
59- onlyUnique : React . PropTypes . bool ,
60- value : React . PropTypes . array . isRequired ,
61- maxTags : React . PropTypes . number
62- }
63-
64- static defaultProps = {
65- className : 'react-tagsinput' ,
66- addKeys : [ 9 , 13 ] ,
67- inputProps : { className : 'react-tagsinput-input' } ,
68- removeKeys : [ 8 ] ,
69- renderInput : defaultRenderInput ,
70- renderTag : defaultRenderTag ,
71- renderLayout : defaultRenderLayout ,
72- tagProps : { className : 'react-tagsinput-tag' , classNameRemove : 'react-tagsinput-remove' } ,
73- onlyUnique : false ,
74- maxTags : - 1
75- }
76-
7749 _removeTag ( index ) {
7850 let value = this . props . value . concat ( [ ] )
7951 if ( index > - 1 && index < value . length ) {
@@ -110,15 +82,17 @@ class TagsInput extends React.Component {
11082 }
11183
11284 handleKeyDown ( e ) {
113- let { value, removeKeys, addKeys} = this . props
85+ let { value, removeKeys, addKeys, validationRegex } = this . props
11486 let { tag} = this . state
11587 let empty = tag === ''
11688 let add = addKeys . indexOf ( e . keyCode ) !== - 1
11789 let remove = removeKeys . indexOf ( e . keyCode ) !== - 1
11890
11991 if ( add ) {
12092 e . preventDefault ( )
121- this . _addTag ( tag )
93+ if ( validationRegex . test ( tag ) ) {
94+ this . _addTag ( tag )
95+ }
12296 }
12397
12498 if ( remove && value . length > 0 && empty ) {
@@ -184,4 +158,34 @@ class TagsInput extends React.Component {
184158 }
185159}
186160
161+ TagsInput . propTypes = {
162+ addKeys : PropTypes . array ,
163+ addOnBlur : PropTypes . bool ,
164+ inputProps : PropTypes . object ,
165+ onChange : PropTypes . func . isRequired ,
166+ removeKeys : PropTypes . array ,
167+ renderInput : PropTypes . func ,
168+ renderTag : PropTypes . func ,
169+ renderLayout : PropTypes . func ,
170+ tagProps : PropTypes . object ,
171+ onlyUnique : PropTypes . bool ,
172+ value : PropTypes . array . isRequired ,
173+ maxTags : PropTypes . number ,
174+ validationRegex : PropTypes . regexp
175+ }
176+
177+ TagsInput . defaultProps = {
178+ className : 'react-tagsinput' ,
179+ addKeys : [ 9 , 13 ] ,
180+ inputProps : { className : 'react-tagsinput-input' } ,
181+ removeKeys : [ 8 ] ,
182+ renderInput : defaultRenderInput ,
183+ renderTag : defaultRenderTag ,
184+ renderLayout : defaultRenderLayout ,
185+ tagProps : { className : 'react-tagsinput-tag' , classNameRemove : 'react-tagsinput-remove' } ,
186+ onlyUnique : false ,
187+ maxTags : - 1 ,
188+ validationRegex : / .* /
189+ }
190+
187191export default TagsInput
0 commit comments