Skip to content

Instantly share code, notes, and snippets.

@jonathanharrell
Last active July 7, 2018 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanharrell/efc100227b35b2e11c2ead6368bf23e4 to your computer and use it in GitHub Desktop.
Save jonathanharrell/efc100227b35b2e11c2ead6368bf23e4 to your computer and use it in GitHub Desktop.
React TagListSearch Component (with render props)
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