Skip to content

Commit c9b6bc6

Browse files
author
Ola Holmström
committed
update version and add @pedroparra as contributor
1 parent caa86aa commit c9b6bc6

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.3.0 (2016-02-21)
2+
3+
* add `maxTags` prop.
4+
15
### 3.2.0 (2016-02-15)
26

37
* add `onlyUnique` prop.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Look at [react-tagsinput.css](./react-tagsinput.css) for a basic style.
154154
* Tay Yang Shun (@yangshun)
155155
* Trevor Hutto (@huttotw)
156156
* David L. Goldberg (@DavidLGoldberg)
157+
* Pedro J. Parra (@pedroparra)
157158

158159

159160
---

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tagsinput",
3-
"version": "3.2.1",
3+
"version": "3.3.0",
44
"description": "Simple react.js component for inputing tags",
55
"main": "react-tagsinput.js",
66
"peerDependencies": {

react-tagsinput.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@
103103
value: function _clearInput() {
104104
this.setState({ tag: '' });
105105
}
106+
}, {
107+
key: '_maxTags',
108+
value: function _maxTags(tags) {
109+
return this.props.maxTags !== -1 ? tags < this.props.maxTags : true;
110+
}
106111
}, {
107112
key: '_addTag',
108113
value: function _addTag(tag) {
109-
var _props = this.props;
110-
var onlyUnique = _props.onlyUnique;
111-
var maxTags = _props.maxTags;
114+
var onlyUnique = this.props.onlyUnique;
112115

113116
var isUnique = this.props.value.indexOf(tag) === -1;
114-
var limit = maxTags ? this.props.value.length < maxTags : true;
117+
var limit = this._maxTags(this.props.value.length);
115118
if (tag !== '' && limit && (isUnique || !onlyUnique)) {
116119
var value = this.props.value.concat([tag]);
117120
this.props.onChange(value);
@@ -131,10 +134,10 @@
131134
}, {
132135
key: 'handleKeyDown',
133136
value: function handleKeyDown(e) {
134-
var _props2 = this.props;
135-
var value = _props2.value;
136-
var removeKeys = _props2.removeKeys;
137-
var addKeys = _props2.addKeys;
137+
var _props = this.props;
138+
var value = _props.value;
139+
var removeKeys = _props.removeKeys;
140+
var addKeys = _props.addKeys;
138141
var tag = this.state.tag;
139142

140143
var empty = tag === '';
@@ -198,18 +201,18 @@
198201
value: function render() {
199202
var _this = this;
200203

201-
var _props3 = this.props;
202-
var value = _props3.value;
203-
var onChange = _props3.onChange;
204-
var inputProps = _props3.inputProps;
205-
var tagProps = _props3.tagProps;
206-
var renderLayout = _props3.renderLayout;
207-
var renderTag = _props3.renderTag;
208-
var renderInput = _props3.renderInput;
209-
var addKeys = _props3.addKeys;
210-
var removeKeys = _props3.removeKeys;
204+
var _props2 = this.props;
205+
var value = _props2.value;
206+
var onChange = _props2.onChange;
207+
var inputProps = _props2.inputProps;
208+
var tagProps = _props2.tagProps;
209+
var renderLayout = _props2.renderLayout;
210+
var renderTag = _props2.renderTag;
211+
var renderInput = _props2.renderInput;
212+
var addKeys = _props2.addKeys;
213+
var removeKeys = _props2.removeKeys;
211214

212-
var other = _objectWithoutProperties(_props3, ['value', 'onChange', 'inputProps', 'tagProps', 'renderLayout', 'renderTag', 'renderInput', 'addKeys', 'removeKeys']);
215+
var other = _objectWithoutProperties(_props2, ['value', 'onChange', 'inputProps', 'tagProps', 'renderLayout', 'renderTag', 'renderInput', 'addKeys', 'removeKeys']);
213216

214217
var tag = this.state.tag;
215218

@@ -260,7 +263,7 @@
260263
renderLayout: defaultRenderLayout,
261264
tagProps: { className: 'react-tagsinput-tag', classNameRemove: 'react-tagsinput-remove' },
262265
onlyUnique: false,
263-
maxTags: 0
266+
maxTags: -1
264267
},
265268
enumerable: true
266269
}]);

test/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,22 @@ describe("TagsInput", () => {
205205
assert.equal(comp.len(), 0, "there should be no tags");
206206
});
207207

208-
it("should limit tags added", () => {
208+
it("should limit tags added to 0", () => {
209209
let comp = TestUtils.renderIntoDocument(<TestComponent maxTags={0} />);
210210
let tag = randstring();
211211
add(comp, tag);
212212
add(comp, tag);
213213
assert.equal(comp.len(), 0, "there should be 0 tags");
214214
});
215215

216+
it("should limit tags added to 1", () => {
217+
let comp = TestUtils.renderIntoDocument(<TestComponent maxTags={1} />);
218+
let tag = randstring();
219+
add(comp, tag);
220+
add(comp, tag);
221+
assert.equal(comp.len(), 1, "there should be 1 tags");
222+
});
223+
216224
it("should add props to tag", () => {
217225
let comp = TestUtils.renderIntoDocument(<TestComponent tagProps={{className: "test"}} />);
218226
let tag = randstring();

0 commit comments

Comments
 (0)