-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX (searchFn)[#101] searchFn callback should only call once when typ…
…ing in the search bar, #134, #133 (#136) * Working searchFn example. * Remove debug code. * Undo indentation * Restore changes. * Remove debug code. * Restore return. * Add test for a custom function. * Add test coverage for custom search function. * Apply code review suggestions. * Reset searchResults on blur. * Clear search results on dropdown; update search results on options change.
- Loading branch information
Pattie Reaves
authored
Nov 17, 2020
1 parent
eccff4c
commit 64a737a
Showing
9 changed files
with
247 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { Heading } from './components/Heading'; | ||
import Select from '../../../src'; | ||
|
||
import { | ||
getByPath, | ||
} from '../../../src/util'; | ||
|
||
const WithSearchFn = ({ options, title }) => { | ||
const onSearch = ({ props, state, methods }) => { | ||
console.log({ props, state, methods }); | ||
|
||
const regexp = new RegExp(methods.safeString(state.search), 'i'); | ||
return methods | ||
.sortBy() | ||
.filter((item) => | ||
regexp.test(getByPath(item, props.searchBy) || getByPath(item, props.valueField)) | ||
); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Heading | ||
title={title} | ||
source="https://github.com/sanusart/react-dropdown-select/tree/master/docs/src/examples/WithSearchFn.js" | ||
/> | ||
<Select | ||
options={options} | ||
searchFn={onSearch} | ||
/> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
WithSearchFn.propTypes = {}; | ||
|
||
export default WithSearchFn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.