Skip to content

Commit

Permalink
fix issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Holmström committed May 28, 2015
1 parent e787447 commit 8020070
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -187,6 +187,7 @@ An example of how to use React components instead of strings as tags can be foun
* Artem Vovsya (@avovsya)
* scott c (@scoarescoare)
* junk (@jedverity)
* Buz Carter (@buzcarter)

---

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -4,7 +4,7 @@
"react-tagsinput.js",
"react-tagsinput.css"
],
"version": "1.3.3",
"version": "1.3.4",
"homepage": "https://github.com/olahol/react-tagsinput",
"description": "Simple react.js component for inputing tags",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-tagsinput",
"version": "1.3.3",
"version": "1.3.4",
"description": "Simple react.js component for inputing tags",
"main": "react-tagsinput.js",
"dependencies": {
Expand Down
14 changes: 11 additions & 3 deletions react-tagsinput.js
Expand Up @@ -126,8 +126,10 @@

this.setState(function (state) {
var newValue = fn(state.value);
this.props.onChange(newValue, tag);
return { value: newValue };
if (newValue) {
this.props.onChange(newValue, tag);
return { value: newValue };
}
});
}

Expand Down Expand Up @@ -195,7 +197,13 @@
for (var i = 0; i < clone.length; i += 1) {
if (clone[i] === tag) {
clone.splice(i, 1);
this.props.onTagRemove(tag);

this.setState({
invalid: false
}, function () {
this.props.onTagRemove(tag);
});

return clone;
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/index.js
Expand Up @@ -373,6 +373,21 @@ describe("TagsInput", function () {

addTag(tagsinput, "");
});

it("if nothing has changed callbacks should not fire", function () {
var tagsinput = createTagsInput({
valueLink: null,
onTagAdd: function (tag) {
assert.ok(false);
},
onTagRemove: function (tag) {
assert.ok(false);
}
}).tagsInput();

tagsinput.addTag("");
tagsinput.removeTag("tag1");
});
});

describe("bugs", function () {
Expand Down Expand Up @@ -400,5 +415,20 @@ describe("TagsInput", function () {
assert.equal(tags[1], "bbb");
assert.equal(tags[2], "ccc");
});

it("issue #15", function () {
var tagsinput = createTagsInput({
valueLink: null,
onTagAdd: function (tag) {
assert.equal(tagsinput.getTags().length, 1);
},
onTagRemove: function (tag) {
assert.equal(tagsinput.getTags().length, 0);
}
}).tagsInput();

tagsinput.addTag("tag1");
tagsinput.removeTag("tag1");
});
});
});

0 comments on commit 8020070

Please sign in to comment.