-
-
Notifications
You must be signed in to change notification settings - Fork 208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be even simpler. Why do we need to change any state for this? 🤔
@@ -253,7 +253,7 @@ class ChipInput extends React.Component { | |||
} | |||
|
|||
handleKeyDown = (event) => { | |||
this.setState({keyPressed: false}) | |||
this.setState({keyPressed: false, preventChipCreation: false}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this state and handle the keyDown event? Only checking what the function says in handleAddChip
should be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's all because of the this.clearInput()
inside handleKeyUp
i need some more state to know when to prevent also the handleKeyUp
@@ -304,6 +304,7 @@ class ChipInput extends React.Component { | |||
} | |||
|
|||
handleKeyUp = (event) => { | |||
if (this.state.preventChipCreation) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/ChipInput.js
Outdated
@@ -324,6 +325,9 @@ class ChipInput extends React.Component { | |||
} | |||
|
|||
handleAddChip (chip) { | |||
if (this.props.onBeforeRequestAdd && !this.props.onBeforeRequestAdd(chip)) { | |||
return this.setState({ preventChipCreation }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple return
should be sufficient here. Also, where does the preventChipCreation
variable come from here?
Looks fine to me now, @kalimantos. Is there anything you want to do on this before I merge the PR? |
When the first chip is verified, the content of input it continues clearing |
@jriuamb I can't reproduce this. 😮 |
I am new to github. I'm trying to understand how it works. I downloaded the master branch version 0.18.1. I tried the Controlled Input form StoryBook.
Also happens that the console shows react errors. |
@jriuamb Thanks for the reproduction example! I'll look into this soon. |
solves #145
onBeforeRequestAdd(chip): Boolean