-
Notifications
You must be signed in to change notification settings - Fork 529
Trigger event on enter #25 #83
Trigger event on enter #25 #83
Conversation
@@ -10,6 +10,7 @@ let Autocomplete = React.createClass({ | |||
initialValue: React.PropTypes.any, | |||
onChange: React.PropTypes.func, | |||
onSelect: React.PropTypes.func, | |||
onSearch: React.PropTypes.func, |
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.
Feel free to suggest another name for this props.
What would you do as a result of |
You can do whatever you need inside onSearch function. For instance, it's a improvement referenced to the issue #25, in this function you can submit queries that aren't in the autocomplete options.. |
onSearch => (currentValue, setValueCallback) {
setValueCallback(currentValue.split(',').reverse().join());
} |
…. Please use ReactDOM.render" This reverts commit eecee25.
You're right with that, I'll revert the commit 👍 Regarding to the event, it's a great idea, I'll update |
Let's take a step back and review this proposal:
I'd argue that the first point is the responsibility of the surrounding form, not the input element. Remember, there's already a default behaviour attached to hitting return in an input element, which is to submit the form (naming the callback As for the second point, there's already work in progress (#65) on removing I still don't understand the need for this API. No one has offered an example where this proposed callback would be any better than simply using |
I agree with several thing you mentioned, this new API has emerged from an issue requested by cleercode (#25). Do you really think we need this functionality?. I have in mind to decline this pull request |
I honestly don't think it's needed, but I'm not the correct person to argue for its existence since I don't know the problem well enough. |
I don't see how this is easily implemented outside of the library. To restate the goal, there are two desired actions:
@CMTegner you mentioned that it is the job of the surronding form, suggesting that should be wrapped in a form? But that along with other options (assigning a listener to the search event if making input type search, or listening for an enter key press) are difficult because the focus remains on the input field while using the arrow keys to navigate through the suggested results. How can we tell whether any item is currently highlighted? Or how can we watch for an event that will only fire if no item is highlighted given that "onSubmit" events will fire with or without something selected? |
The Autocomplete component will receive a function as a propType that will be called when the following events occurs.
The function receives a parameter which is the value entered on the input. Thus, who instantiate the Autocomplete component could make any action with that value. For this specific issue, we need to make a service call with this value.
By implementing this improvement with this approach we reach the next benefits: