Skip to content

Commit

Permalink
v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Delpoux committed Jan 30, 2018
1 parent 7a906ae commit 3946a65
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 62 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.3.0 - 2018-01-30

* Added: Original prediction ad argument to `onSelectSuggest` by @emguide

# 3.2.1 - 2017-11-22

* Updated: Use React 15 to run test because React 16 is not fully compatible
Expand Down
122 changes: 61 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,60 @@ import GooglePlacesSuggest from "react-google-places-suggest"
const MY_API_KEY = "AIzaSyDwsdjfskhdbfjsdjbfksiTgnoriOAoUOgsUqOs10J0" // fake

export default class GoogleSuggest extends React.Component {
state = {
search: "",
value: "",
}

handleInputChange(e) {
this.setState({search: e.target.value, value: e.target.value})
}

handleSelectSuggest(suggest) {
console.log(suggest) // eslint-disable-line
this.setState({search: "", value: suggest.formatted_address})
}

render() {
const {search, value} = this.state
return (
<ReactGoogleMapLoader
params={{
key: MY_API_KEY,
libraries: "places,geocode",
}}
render={googleMaps =>
googleMaps && (
<ReactGooglePlacesSuggest
googleMaps={googleMaps}
autocompletionRequest={{
input: search,
// Optional options
// https://developers.google.com/maps/documentation/javascript/reference?hl=fr#AutocompletionRequest
}}
// Optional props
onSelectSuggest={this.handleSelectSuggest.bind(this)}
textNoResults="My custom no results text" // null or "" if you want to disable the no results item
customRender={prediction => (
<div className="customWrapper">
{prediction
? prediction.description
: "My custom no results text"}
</div>
)}
>
<input
type="text"
value={value}
placeholder="Search a location"
onChange={this.handleInputChange.bind(this)}
/>
</ReactGooglePlacesSuggest>
)
}
/>
)
}
state = {
search: "",
value: "",
}

handleInputChange = e => {
this.setState({search: e.target.value, value: e.target.value})
}

handleSelectSuggest = (geocodedPrediction, originalPrediction) => {
console.log(geocodedPrediction, originalPrediction) // eslint-disable-line
this.setState({search: "", value: geocodedPrediction.formatted_address})
}

render() {
const {search, value} = this.state
return (
<ReactGoogleMapLoader
params={{
key: MY_API_KEY,
libraries: "places,geocode",
}}
render={googleMaps =>
googleMaps && (
<ReactGooglePlacesSuggest
googleMaps={googleMaps}
autocompletionRequest={{
input: search,
// Optional options
// https://developers.google.com/maps/documentation/javascript/reference?hl=fr#AutocompletionRequest
}}
// Optional props
onSelectSuggest={this.handleSelectSuggest}
textNoResults="My custom no results text" // null or "" if you want to disable the no results item
customRender={prediction => (
<div className="customWrapper">
{prediction
? prediction.description
: "My custom no results text"}
</div>
)}
>
<input
type="text"
value={value}
placeholder="Search a location"
onChange={this.handleInputChange}
/>
</ReactGooglePlacesSuggest>
)
}
/>
)
}
}
```

Expand All @@ -98,13 +98,13 @@ See [Demo page][github-page]

## Props

| Name | PropType | Description | Example |
| --------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| googleMaps | object | injected by `react-google-maps-loader` | - |
| onSelectSuggest | function | Handle click on suggest | `prediction => {console.log(prediction)}` |
| customRender | function | Customize list item | `prediction => prediction ? prediction.description : "no results"` |
| autocompletionRequest | object | [Google map object Object](https://developers.google.com/maps/documentation/javascript/reference?hl=fr#AutocompletionRequest) | `{input: "Toulouse"}` |
| textNoResults | String | No results text, null to disable | `No results` |
| Name | PropType | Description | Example |
| --------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| googleMaps | object | injected by `react-google-maps-loader` | - |
| onSelectSuggest | function | Handle click on suggest | `(geocodedPrediction, originalPrediction) => {console.log(geocodedPrediction, originalPrediction)}` |
| customRender | function | Customize list item | `prediction => prediction ? prediction.description : "no results"` |
| autocompletionRequest | object | [Google map object Object](https://developers.google.com/maps/documentation/javascript/reference?hl=fr#AutocompletionRequest) | `{input: "Toulouse"}` |
| textNoResults | String | No results text, null to disable | `No results` |

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-google-places-suggest",
"version": "3.2.2",
"version": "3.3.0",
"author": {
"name": "Cédric Delpoux",
"email": "[email protected]"
Expand Down

0 comments on commit 3946a65

Please sign in to comment.