Skip to content

Commit

Permalink
fix(tags-field): prevent key events to avoid sending parent form when…
Browse files Browse the repository at this point in the history
… adding tags
  • Loading branch information
dackmin committed Feb 19, 2019
1 parent 8838d35 commit 854bc52
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/TagsField.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,17 @@ class TagsField extends React.Component {
return true;
}

onKeyDown(e) {
onKeyDown(event) {
event.preventDefault();

if (this.props.disabled) {
return false;
}

const {selected, input, value} = this.state;

if (
(e.which === 8 || e.keyCode === 8) && // BACKSPACE
(event.which === 8 || event.keyCode === 8) && // BACKSPACE
input.trim() === '' &&
value.length > 0
) {
Expand All @@ -162,24 +164,26 @@ class TagsField extends React.Component {
this.remove(selected);
}
return false;
} else if (e.which === 27 || e.keyCode === 27) { // ESC
} else if (event.which === 27 || event.keyCode === 27) { // ESC
this.unselectItem();
}

return true;
return false;
}

onKeyPress(e) {
onKeyPress(event) {
event.preventDefault();

if (this.props.disabled) {
return false;
}

if (e.which === 13 || e.keyCode === 13) {
if (event.which === 13 || event.keyCode === 13) {
this.add(this.state.input);
return false;
}

return true;
return false;
}

add(item) {
Expand Down

0 comments on commit 854bc52

Please sign in to comment.