react-typeahead icon indicating copy to clipboard operation
react-typeahead copied to clipboard

Allow value to be changed from higher level

Open danieljuhl opened this issue 9 years ago • 10 comments

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.

danieljuhl avatar Jul 29 '15 10:07 danieljuhl

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 avatar Aug 10 '15 10:08 yurynix

@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 avatar Aug 22 '15 13:08 barbalex

@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 avatar Aug 24 '15 06:08 yurynix

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

RobbieClarken avatar Sep 30 '15 05:09 RobbieClarken

#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 avatar Oct 09 '15 18:10 smith-kyle

@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 avatar Oct 10 '15 08:10 yurynix

@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 avatar Oct 10 '15 08:10 danieljuhl

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

yurynix avatar Oct 10 '15 08:10 yurynix

@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 avatar Oct 10 '15 08:10 danieljuhl

@danieljuhl Thanks!

yurynix avatar Oct 12 '15 11:10 yurynix