fmoo / react-typeahead

Pure react-based typeahead and typeahead-tokenizer
ISC License
677 stars 231 forks source link

Allow value to be changed from higher level #108

Open danieljuhl opened 9 years ago

danieljuhl commented 9 years ago

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.

yurynix commented 9 years ago

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

barbalex commented 9 years ago

@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

yurynix commented 9 years ago

@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

RobbieClarken commented 8 years ago

@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.

smith-kyle commented 8 years ago

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.

yurynix commented 8 years ago

@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.

danieljuhl commented 8 years ago

@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.

yurynix commented 8 years ago

@danieljuhl Sounds great, can you provide a link for your changes?

danieljuhl commented 8 years ago

@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 react@0.14.0 - it was actually the main goal

yurynix commented 8 years ago

@danieljuhl Thanks!