Skip to content

Instantly share code, notes, and snippets.

@husek
Created November 21, 2017 00:26
Show Gist options
  • Save husek/f59b259cd0392bc0faeab7d7392339ad to your computer and use it in GitHub Desktop.
Save husek/f59b259cd0392bc0faeab7d7392339ad to your computer and use it in GitHub Desktop.
react-select-plus keys not working example
import React from 'react';
import createClass from 'create-react-class';
import Select from 'react-select-plus';
import SearchState from '../data/searchState';
var ExampleDemo = createClass({
displayName: 'ExampleDemo',
getInitialState() {
return {
currentLocation: null
};
},
handleOnChange(value) {
const { multi } = this.state;
if (multi) {
this.setState({ multiValue: value });
} else {
this.setState({ value });
}
},
getLocationList(input, callback) {
console.log(SearchState);
return callback(null, { options: SearchState });
},
renderOption(option) {
return (
<span>
{option.name}
</span>
);
},
valueRender(options) {
return (
<span>{options.name}, {options.level}</span>
);
},
handleChange(option) {
if (option && option.id) {
this.setState({
currentLocation: option
});
}
},
handleFocus() {
this.setState({
currentLocation: '',
previousLocation: this.state.currentLocation
});
},
handleBlur() {
if (!this.state.currentLocation || this.state.currentLocation === '') {
this.setState({
currentLocation: this.state.previousLocation,
previousLocation: this.state.currentLocation
});
}
},
setInput(inputValue) {
this.setState({ inputValue });
},
render() {
return (
<div className="section">
<Select.Async
onChange={this.handleChange}
autoload={false}
loadOptions={this.getLocationList}
onInputChange={this.setInput}
value={this.state.currentLocation}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
instanceId="searchBar"
name="search-bar"
labelKey="name"
valueLabel="id"
clearable={false}
valueRenderer={this.valueRender}
optionRenderer={this.renderOption}
/>
</div>
);
}
});
module.exports = ExampleDemo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment