Handle Searching for Numbers#41
Conversation
A quick fix for issue 40 (selvagsz#40). Feel free to adjust if this is suboptimal.
| if (typeof (option[index] || '') === 'string') { | ||
| return (option[index] || '').toLowerCase().indexOf(searchTerm) !== -1; | ||
| } | ||
| return (String(option[index]) || '').toLowerCase().indexOf(searchTerm) !== -1; |
There was a problem hiding this comment.
String(1) => "1"
String(null) => "null"
String(undefined) => "undefined"@SCasarotto While stringifying the number is fine; null & undefined values shouldn't be part of search. We can exclude them. Something like
//...
return makeArray(searchIndices).some(index => {
let value = option[index];
return !isNone(value) && String(value).toLowerCase().indexOf(searchTerm) !== -1;
});
//...
export const isNone = value => value === null || value === undefined;There was a problem hiding this comment.
@SCasarotto It would be great if you could also add unit tests for the matcher func under src/__tests__/utils-test.js. Possible ?
There was a problem hiding this comment.
I'd be happy to try to add some tests and update the code as you suggested. I am not sure when I will be able to fit this in though.
|
@SCasarotto No worries, I'll try merging on a bugfix branch & take it over |
|
Thanks. I started trying to write some tests but seemed to have issues getting jest to notice my tests and then had to run to meetings. If I can assist I really will try. I want to try to give back to something I use if I can. |
|
@SCasarotto Cool then. Tests are been ignored because of these lines https://github.com/selvagsz/react-power-select/blob/master/package.json#L37-L39 You can proceed doing the following steps,
|
|
Ah, thank you. I started looking around but didn't see that line. Awesome! I will keep you posted and thanks for bearing with me. |
|
@selvagsz I have written tests and improved the matcher. I have been working in my local version of |
|
@SCasarotto You don't have push access to this repo. Can you please raise another PR from your fork ? |
A quick fix for #40. Feel free to adjust if this is suboptimal.
In my quick testing, this seems to resolve the issue.