Skip to content

Commit 7e2f1f0

Browse files
committed
Fix default for limit
1 parent d2c0d60 commit 7e2f1f0

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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", () => {

0 commit comments

Comments
 (0)