ydeshayes / googlePlaceAutocomplete

Wrapper on top of the material-ui AutoComplete component that use google place api
https://ydeshayes.github.io/googlePlaceAutocomplete/
26 stars 12 forks source link

Pass componentRestrictions to autocompleteService #8

Closed jackgardner closed 7 years ago

jackgardner commented 7 years ago

Hi, sometimes it is useful to use ComponentRestrictions to restrict the place predictions API to certain countries. This PR will allow ComponentRestrictions to be passed through props on the component.

I also noticed there were a few inconsistencies with the linting etc and have included those as part of this PR in a seperate commit as they are only small, just let me know if you would like a seperate PR for those.

ydeshayes commented 7 years ago

Hi ! thanks for the PR !

Maybe it can be better to have the componentRestrictions props to equal an object like https://developers.google.com/maps/documentation/javascript/reference#GeocoderComponentRestrictions ?

I will add keyword-spacing rule in eslint to have a consistent spacing.

jackgardner commented 7 years ago

Hi,

getPlacePredictions accepts a different object, limited to country only: (unless I am misreading the docs)

https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions

It might be clearer if the componentRestrictions prop reflects this type though, so instead of

restrictions: PropTypes.oneOfType([
  PropTypes.string,
  PropTypes.arrayOf(PropTypes.string)
])

it could be

restrictions: PropTypes.shape({ 
  country: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.arrayOf(PropTypes.string)
  ])
})

What do you think?

ydeshayes commented 7 years ago

Yes ok, I miss the part where getPlacePredictions only accept country ^^

Agreed with

restrictions: PropTypes.shape({ 
  country: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.arrayOf(PropTypes.string)
  ])
})

:)

jackgardner commented 7 years ago

Great - let me know what you think

ydeshayes commented 7 years ago

Thanks !