reactjs / react-autocomplete

WAI-ARIA compliant React autocomplete (combobox) component
MIT License
2.17k stars 532 forks source link

[added] optional custom function to compare input value to list option values #294

Open HUSSTECH opened 6 years ago

HUSSTECH commented 6 years ago

fixes #239, #266

Allows us to specify a custom comparison function to evaluate matches. In the same way the flexibility is provided to fully control the options list via your own code/logic, it would be good to be able to do the same for highlight matches. The issues above where users would like to check for string contains raher than startsWith will be able to do something like the following:

valueItemComparison={(optionItemValue, inputValue) => {  
            return optionItemValue.toLowerCase().includes(inputValue.toLowerCase())  
          }} 

This is a backwards compatible change, if the prop is not specified, then the old comparison logic using indexOf() is the default.

Possible improvements:

  1. naming of the comparison function and its input variables (a minor point, but I don't think they fit with the rest of the libs naming style)