-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is focusFirstSuggestion working #199
Comments
I apologise for not being clear, but I wasn't sure why the behaviour I was seeing was happening. After seeing your Codepen, thank for that, I went back to my codebase and narrowed down what was causing the problem. It was caused by the following line. suggestions: [].concat(suggestions) But I am not quite sure why. Here is a Codepen example. I get the same behaviour with slice too suggestions: suggestions.slice() |
Thanks @avjpl, now I see that Up/Down doesn't work properly. @rickhanlonii Could you have a look? |
@rickhanlonii Any luck? |
@moroshko not yet, last week was pretty busy. I'll take a look this week. |
I've just hit this problem, too. If you take a look at componentWillReceiveProps(nextProps) {
if (nextProps.suggestions !== this.props.suggestions) {
const {
suggestions, inputProps, shouldRenderSuggestions,
isCollapsed, revealSuggestions, lastAction
} = nextProps;
const { value } = inputProps;
if (suggestions.length > 0 && shouldRenderSuggestions(value)) {
this.maybeFocusFirstSuggestion();
if (isCollapsed && lastAction !== 'click' && lastAction !== 'enter') {
revealSuggestions();
}
}
}
} This code is doing an identity comparison on the list of suggestions. So if you compute the This code should probably do a deep array comparison instead. |
On second thought, a deep comparison is probably wrong. What the code should actually do is check whether either nothing is selected or whatever is selected is no longer in the list of suggestions, and only in this case select the first element. That's still in O(n) though, so it's not really faster than doing a deep array comparison. Also note that if your state management code mutates // suggestions is ['Hamburg', 'Havana']
suggestions.length = 0
suggestions.unshift('Bangkok', 'Berlin') the implementation above will fail to detect the change. |
Probably makes sense to shallowly compare |
This is fixed in 5.0.1 now. |
Can confirm, 5.0.1 fixes the issue for me. Thank you for fixing this so quickly! |
Great diagnosis @fixpunkt! |
By added focusFirstSuggestion: true break the selection. It only selects the first suggestion. Is there anything else apart from setting this to true that needs to be done?
This is the object I am paasing to autosuggest.
The text was updated successfully, but these errors were encountered: