react-typeahead
react-typeahead copied to clipboard
Allow value to be changed from higher level
It seems that value
is only used on component construction, and not respected if changed afterwards.
I would like to be able to change the value / default value of the component based on an external value.
I had a similar scenario where I would render typehead with different value when user clicked on something, so I've made the following modification that seems to work for me: https://github.com/yurynix/react-typeahead/commit/1a963818adeded7d1400e44fd521af2df4c246db
@yurynix did you make a pull request? I need this feature too. For instance to empty the input when the user clicks on an x symbol at it's right side
@barbalex I don't mind making a pull request, but I'm looking for getting some feedback first, Since I'm not yet very familiar with TypeAhead's inner stuff.
Same issue discussed here: https://github.com/fmoo/react-typeahead/issues/74
@yurynix Your proposed change would be very useful for me too. I wish I could provide feedback but I'm not familiar enough with the module either.
#133 Seems to solve a niche problem. If value
could instead be modified directly through the props then you could do all this from the Typeahead
parent component.
@smith-kyle
Typeahead already has all the mechanics: finding object
by value
, converting object
to display value
, so we might as well let Typeahead
handling choosing the right object
by value
at props.
As you can see from the commit, the code change is very minor.
@yurynix I've been testing you change, which works great in our setup, but I made two minor changes. First I allowed to clear the typeahead by passing a falsy value to Typeahead
, furthermore I modified the selection, so that it does not check for only one result, but instead it checks if the first option is equal to the input value. The reason for this is that even when the input value is an exact match, the fuzzy search can suggest other results, and I think that setting the value programmatic, should not be a fuzzy pick. I also look to make a change, so that the defaultValue can be used instead, and in that case only updates the value if the user has not made any typing.
@danieljuhl Sounds great, can you provide a link for your changes?
@yurynix https://github.com/kodyl/react-typeahead/tree/react-0.14, but please notice that I also made changes to avoid errors and warnings when used with [email protected]
- it was actually the main goal
@danieljuhl Thanks!