fmoo / react-typeahead

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

Using setEntryText or setting a typeahead's entryValue state variable with a ref/from outside the typeahead component has unwanted side effects #181

Open vrunjeti opened 8 years ago

vrunjeti commented 8 years ago

I'm trying to set the value of the typeahead's input, but doing so with setEntryText or setting its entryValue state also renders the dropdown with one option containing the chosen value.

The solution suggested in #116 works for setting the input's value, but doing so also displayed the dropdown containing one option with that value. This brought up further issues with trying to manually blur the input. Unlike the solution from #169, which depends on re-rendering the typeahead component from the top, in this case, calling typeahead.setEntryText or setting its entryValue state variable seems to also trigger something that causes the results dropdown to be displayed.

What I'm wondering is if this coupling was intentional, and if so, why. I would imagine that most people trying to use setEntryText would want to do just that and not have any side effects.

After some more digging around, I found that @yurynix's suggestion from #74 achieves what I'm trying to do with no side effects. Even though this worked for me, I'm still curious about setEntryText's side effects, especially since it doesn't appear to be mentioned in the docs.

Sorry for all these words, I'm just trying to get a better understanding and hopefully help others find solutions to similar problems. Thanks!

vrunjeti commented 8 years ago

Update: I'm not so sure anymore if those side effects are a result of setEntryText. It might have been an issue with my code (oops). However, I'm still curious if anyone has this issue.