Skip to content

Commit

Permalink
Add suggest types and component restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Sutton authored and Cédric Delpoux committed Feb 16, 2017
1 parent 9725784 commit 9ef76d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default GoogleMapLoader(MyGoogleSuggest, {
* `renderSuggest`: Function with one parameter (`renderSuggest: (suggest) => {}`),
* `search`: String - the search query,
* `suggestRadius`: Number - default 20,
* `suggestTypes`: String Array - default [] - accepts string values as defined by [Google API docs](https://developers.google.com/maps/documentation/javascript/places-autocomplete),
* `suggestComponentRestrictions`: Object - default { country: "" } - accepts values defined by [Google API docs](https://developers.google.com/maps/documentation/javascript/places-autocomplete),
* `textNoResults`: String - default "No results" - null to disable,

## Development
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GooglePlacesSuggest extends Component {
}

updateSuggests(search) {
const {googleMaps, suggestRadius} = this.props
const {googleMaps, suggestRadius, suggestTypes, suggestComponentRestrictions} = this.props
const autocompleteService = new googleMaps.places.AutocompleteService()

if (!search) {
Expand All @@ -46,6 +46,8 @@ class GooglePlacesSuggest extends Component {
input: search,
location: new googleMaps.LatLng(0, 0),
radius: suggestRadius,
types: suggestTypes,
componentRestrictions: suggestComponentRestrictions,
}, (googleSuggests) => {
if (!googleSuggests) {
this.setState({suggests: []})
Expand Down Expand Up @@ -188,13 +190,19 @@ GooglePlacesSuggest.propTypes = {
renderSuggest: PropTypes.func,
search: PropTypes.string,
suggestRadius: PropTypes.number,
suggestTypes: PropTypes.array,
suggestComponentRestrictions: PropTypes.object,
textNoResults: PropTypes.string,
}

GooglePlacesSuggest.defaultProps = {
onSelectSuggest: () => {},
search: "",
suggestRadius: 20,
suggestRadius: 20,
suggestTypes: [],
suggestComponentRestrictions: {
country: ""
},
textNoResults: "No results",
}

Expand Down

0 comments on commit 9ef76d8

Please sign in to comment.