fmoo / react-typeahead

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

Option search is being run one change behind #128

Open Mr-Wallet opened 9 years ago

Mr-Wallet commented 9 years ago

When constructing a Typeahead with an array of strings as the object, each change brings up a list of options reflecting the input node's value before the change.

'' > no list
'a' > empty list
'ab' > list matching 'a'
'abc' > list matching 'ab'
'ab' [backspace] > list matching 'abc'
'abPASTED_TEXT' > list matching 'ab'
'abPASTED_TEXTc' > list matching 'abPASTED_TEXT'

Based on stepping through, it seems to be because componentWillReceiveProps is using this.state.entryValue to calculate the options, but the setState({entryValue}) in _onTextEntryUpdated hasn't yet been put into this.state at that point. As a result, even though the correct options are calculated in _onTextEntryUpdated, they're instantly overridden before the render occurs by a recalculation in componentWillReceiveProps using the previous state.

mattvv commented 8 years ago

Also having this issue.

mattvv commented 8 years ago

This seems to work fine on tokenizer though.

smith-kyle commented 8 years ago

I'm experiencing this as well

juanmnl commented 8 years ago

I was experiencing this until i removed defaultValue="" from the component props.

alexjg commented 8 years ago

@fmoo Is there any chance you could take a look at the above PR which fixes this issue?