Last active
August 29, 2015 14:20
-
-
Save ryanflorence/cfab4221074876433a49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// with static data, do filtering and sorting in the client | |
<Autocomplete | |
initialValue="Ma" | |
items={getUnitedStates()} | |
getItemValue={(item) => item.name} | |
shouldItemRender={(item, value) => ( | |
state.name.toLowerCase().indexOf(value.toLowerCase()) !== -1 || | |
state.abbr.toLowerCase().indexOf(value.toLowerCase()) !== -1 | |
)} | |
sortItems={(a, b, value) => ( | |
a.name.toLowerCase().indexOf(value.toLowerCase()) > | |
b.name.toLowerCase().indexOf(value.toLowerCase()) ? 1 : -1 | |
)} | |
renderItem={(item, isHighlighted) => ( | |
<div | |
style={isHighlighted ? styles.highlightedOption : styles.option} | |
key={item.abbr} | |
>{item.name}</div> | |
)} | |
renderEmpty={(value) => ( | |
<div style={{padding: 10}}>No matches for {value}</div> | |
)} | |
/> | |
// or from server data that does sorting/filtering already and we just dump it all in | |
<Autocomplete | |
items={this.state.dynamicItems} | |
getItemValue={(item) => item.name} | |
onChange={(value) => { | |
makeRequest(value, (items) => { | |
this.setState({ dynamicItems: items }) | |
}) | |
}} | |
renderItem={(item, isHighlighted) => ( | |
<div | |
style={isHighlighted ? styles.highlightedOption : styles.option} | |
key={item.abbr} | |
>{item.name}</div> | |
)} | |
renderEmpty={(value) => ( | |
<div style={{padding: 10}}>No matches for {value}</div> | |
)} | |
/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this coming to react-autocomplete?