google-location-autocomplete-react
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,4 +1,6 @@ | ||
/// <reference types="googlemaps" /> | ||
import React from "react"; | ||
interface GoogleAutocompleteProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
apiKey: string; | ||
onPlaceSelected?: (place: google.maps.places.PlaceResult) => void; | ||
} | ||
@@ -8,2 +10,3 @@ declare global { | ||
initAutocomplete?: () => void; | ||
google?: any; | ||
} | ||
@@ -10,0 +13,0 @@ } |
@@ -26,7 +26,13 @@ var __assign = (this && this.__assign) || function () { | ||
var GoogleLocationAutocomplete = function (_a) { | ||
var apiKey = _a.apiKey, props = __rest(_a, ["apiKey"]); | ||
var apiKey = _a.apiKey, onPlaceSelected = _a.onPlaceSelected, props = __rest(_a, ["apiKey", "onPlaceSelected"]); | ||
var inputRef = useRef(null); | ||
var initAutocomplete = function () { | ||
var handlePlaceSelect = function () { | ||
if (inputRef.current) { | ||
new window.google.maps.places.Autocomplete(inputRef.current); | ||
var autocomplete_1 = new window.google.maps.places.Autocomplete(inputRef.current); | ||
autocomplete_1.addListener('place_changed', function () { | ||
var place = autocomplete_1.getPlace(); | ||
if (onPlaceSelected) { | ||
onPlaceSelected(place); | ||
} | ||
}); | ||
} | ||
@@ -39,3 +45,3 @@ }; | ||
} | ||
window.initAutocomplete = initAutocomplete; | ||
window.initAutocomplete = handlePlaceSelect; | ||
var url = "https://maps.googleapis.com/maps/api/js?key=".concat(apiKey, "&libraries=places&callback=initAutocomplete"); | ||
@@ -52,5 +58,5 @@ if (!document.querySelector("script[src=\"".concat(url, "\"]"))) { | ||
}; | ||
}, [apiKey]); | ||
}, [apiKey, onPlaceSelected]); | ||
return _jsx("input", __assign({ ref: inputRef, type: "text" }, props)); | ||
}; | ||
export default GoogleLocationAutocomplete; |
{ | ||
"name": "google-location-autocomplete-react", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/GoogleLocationAutocomplete.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/GoogleLocationAutocomplete.d.ts", |
5454
73