Last active
July 7, 2018 20:32
-
-
Save jonathanharrell/efc100227b35b2e11c2ead6368bf23e4 to your computer and use it in GitHub Desktop.
React TagListSearch Component (with render props)
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
import SearchSelect from './search-select' | |
class TagListSearch extends React.Component { | |
constructor(props) { | |
super(props) | |
} | |
filterMethod (options, query) { | |
return options.filter(option => option.toLowerCase().includes(query.toLowerCase())) | |
} | |
render() { | |
return ( | |
<SearchSelect | |
options={this.props.options} | |
filterMethod={this.filterMethod} | |
render={({results, searchList}) => ( | |
<div className="tag-list-search"> | |
<input | |
type="text" | |
placeholder="Type to search list" | |
onChange={searchList} | |
/> | |
<ul className="tag-list"> | |
{results.map(result => ( | |
<li className="tag" key={result}>{result}</li> | |
))} | |
</ul> | |
</div> | |
)} | |
/> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment