File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ Allow only unique tags, default is `false`.
6868
6969##### maxTags
7070
71- Allow limit number of tags, default is ` 0 ` .
71+ Allow limit number of tags, default is ` -1 ` for infinite .
7272
7373##### addOnBlur
7474
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class TagsInput extends React.Component {
7171 renderLayout : defaultRenderLayout ,
7272 tagProps : { className : 'react-tagsinput-tag' , classNameRemove : 'react-tagsinput-remove' } ,
7373 onlyUnique : false ,
74- maxTags : 0
74+ maxTags : - 1
7575 }
7676
7777 _removeTag ( index ) {
@@ -86,10 +86,14 @@ class TagsInput extends React.Component {
8686 this . setState ( { tag : '' } )
8787 }
8888
89+ _maxTags ( tags ) {
90+ return this . props . maxTags !== - 1 ? tags < this . props . maxTags : true
91+ }
92+
8993 _addTag ( tag ) {
90- let { onlyUnique, maxTags } = this . props
94+ let { onlyUnique} = this . props
9195 let isUnique = this . props . value . indexOf ( tag ) === - 1
92- let limit = maxTags ? this . props . value . length < maxTags : true
96+ let limit = this . _maxTags ( this . props . value . length )
9397 if ( tag !== '' && limit && ( isUnique || ! onlyUnique ) ) {
9498 let value = this . props . value . concat ( [ tag ] )
9599 this . props . onChange ( value )
Original file line number Diff line number Diff line change @@ -206,11 +206,11 @@ describe("TagsInput", () => {
206206 } ) ;
207207
208208 it ( "should limit tags added" , ( ) => {
209- let comp = TestUtils . renderIntoDocument ( < TestComponent maxTags = { 1 } /> ) ;
209+ let comp = TestUtils . renderIntoDocument ( < TestComponent maxTags = { 0 } /> ) ;
210210 let tag = randstring ( ) ;
211211 add ( comp , tag ) ;
212212 add ( comp , tag ) ;
213- assert . equal ( comp . len ( ) , 1 , "there should be one tag " ) ;
213+ assert . equal ( comp . len ( ) , 0 , "there should be 0 tags " ) ;
214214 } ) ;
215215
216216 it ( "should add props to tag" , ( ) => {
You can’t perform that action at this time.
0 commit comments