Uh oh!
There was an error while loading. Please reload this page.
[fixed] #309 - autoHighlight not working unless match is beginning of… - #310
[fixed] #309 - autoHighlight not working unless match is beginning of…#310dsc8x wants to merge 1 commit into
Conversation
| const tree = mount(AutocompleteComponentJSX({})) | ||
| expect(tree.state('highlightedIndex')).toEqual(null) | ||
| tree.setProps({ value: 'a' }) | ||
| tree.setProps({ value: 'ri' }) |
There was a problem hiding this comment.
The item we are matching here is Arizona.
In the old test we typed a, which put the Arizona item first and auto-highlighted it.
But if you typed ri then still Arizona was put as first item, but it was not auto-highlighted, since ri does not match the beginning of Arizona.
With the changes in this PR, Arizona will now correctly be highlighted.
| const itemValueDoesMatch = (itemValue.toLowerCase().indexOf( | ||
| value.toLowerCase() | ||
| ) === 0) | ||
| ) > -1) |
There was a problem hiding this comment.
I'd argue, that itemValueDoesMatch is even unnecessary.
If an item is displayed because it passed the check of shouldItemRender then we can also auto-highlight it if it's the first item in the list.
CMTegner
commented
Feb 4, 2018
The existing logic won't be changed at the moment. See #239 for explanation. |
See #309
The current implementation only auto-highlights an item if the input matches the beginning of the item label.
That's problematic if your
shouldItemRenderimplementation allows matching anywhere in the item label, not just from the start.This PR fixes that.