Skip to content

Commit

Permalink
feat(autocomplete): Clear autocomplete when user clicks outside of th…
Browse files Browse the repository at this point in the history
…e dropdown
  • Loading branch information
hibiken committed Oct 20, 2016
1 parent c004d82 commit cdbf117
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/PlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ const defaultStyles = {
position: 'relative',
paddingBottom: '0px',
},
autocompleteOverlay: {
zIndex: 9998,
},
autocompleteWrapper: {
position: 'absolute',
top: '100%',
backgroundColor: 'white',
border: '1px solid #555',
width: '100%',
zIndex: 9999,
},
autocompleteItem: {
padding: '10px',
Expand Down Expand Up @@ -157,6 +161,17 @@ class PlacesAutocomplete extends React.Component {
return (<label className={this.props.classNames.label || ''}>Location</label>)
}

renderOverlay() {
if (this.state.autocompleteItems.length === 0) { return null }
return (
<div
className="PlacesAutocomplete__overlay"
style={defaultStyles.autocompleteOverlay}
onClick={() => this.clearAutocomplete()}>
</div>
)
}

renderAutocomplete() {
const { autocompleteItems } = this.state
if (autocompleteItems.length === 0) { return null }
Expand Down

0 comments on commit cdbf117

Please sign in to comment.