Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Don't use the state for keyPressed and preventChipCreation. Fixes #258
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Jan 20, 2019
1 parent 64d96e5 commit 0964b09
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ChipInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class ChipInput extends React.Component {

handleKeyDown = (event) => {
const { focusedChip } = this.state
this.setState({ keyPressed: false, preventChipCreation: false })
this._keyPressed = false
this._preventChipCreation = false
if (this.props.onKeyDown) {
// Needed for arrow controls on menu in autocomplete scenario
this.props.onKeyDown(event)
Expand Down Expand Up @@ -298,7 +299,7 @@ class ChipInput extends React.Component {
}

handleKeyUp = (event) => {
if (!this.state.preventChipCreation && this.props.newChipKeyCodes.indexOf(event.keyCode) > 0 && this.state.keyPressed) {
if (!this._preventChipCreation && this.props.newChipKeyCodes.indexOf(event.keyCode) > 0 && this._keyPressed) {
this.clearInput()
} else {
this.setState({ inputValue: event.target.value })
Expand All @@ -307,7 +308,7 @@ class ChipInput extends React.Component {
}

handleKeyPress = (event) => {
this.setState({ keyPressed: true })
this._keyPressed = true
if (this.props.onKeyPress) { this.props.onKeyPress(event) }
}

Expand All @@ -328,7 +329,7 @@ class ChipInput extends React.Component {
*/
handleAddChip (chip) {
if (this.props.onBeforeAdd && !this.props.onBeforeAdd(chip)) {
this.setState({ preventChipCreation: true })
this._preventChipCreation = true
return false
}
this.setState({ inputValue: '' })
Expand Down

0 comments on commit 0964b09

Please sign in to comment.