Created
June 9, 2016 02:20
-
-
Save zanedev/9f2684433493f1b29398bd7357819fb8 to your computer and use it in GitHub Desktop.
winterfell react autosuggest custom input wrapper
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
import React from 'react'; | |
import Geosuggest from 'react-geosuggest'; | |
class GeoSuggestCustomInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: this.props.value, | |
}; | |
this.handleChange = this.handleChange.bind(this); | |
} | |
handleChange(address) { | |
this.setState({ | |
value: address, | |
}, this.props.onChange.bind(null, address)); | |
} | |
render() { | |
return ( | |
<Geosuggest | |
name={this.props.name} | |
id={this.props.id} | |
aria-labelledby={this.props.labelId} | |
className={this.props.classes.input} | |
placeholder={this.props.placeholder} | |
value={this.state.value} | |
required={this.props.required ? 'required' : undefined} | |
onChange={this.handleChange} | |
onKeyDown={this.props.onKeyDown} | |
onSuggestSelect={this.handleChange} | |
/> | |
); | |
} | |
} | |
GeoSuggestCustomInput.defaultProps = { | |
classes: {}, | |
name: undefined, | |
id: undefined, | |
value: undefined, | |
placeholder: undefined, | |
onChange: () => {}, | |
onBlur: () => {}, | |
onKeyDown: () => {}, | |
onSuggestSelect: () => {}, | |
}; | |
export default GeoSuggestCustomInput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment