File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,20 @@ function usePlacesWidget(props) {
99
99
return function ( ) {
100
100
return event . current ? event . current . remove ( ) : undefined ;
101
101
} ;
102
- } , [ ] ) ; // Autofill workaround adapted from https://stackoverflow.com/questions/29931712/chrome-autofill-covers-autocomplete-for-google-maps-api-v3/49161445#49161445
102
+ } , [ ] ) ;
103
+ ( 0 , _react . useEffect ) ( function ( ) {
104
+ if ( autocompleteRef . current && onPlaceSelected ) {
105
+ event . current = autocompleteRef . current . addListener ( "place_changed" , function ( ) {
106
+ if ( onPlaceSelected && autocompleteRef && autocompleteRef . current ) {
107
+ onPlaceSelected ( autocompleteRef . current . getPlace ( ) , inputRef . current , autocompleteRef . current ) ;
108
+ }
109
+ } ) ;
110
+ }
111
+
112
+ return function ( ) {
113
+ return event . current ? event . current . remove ( ) : undefined ;
114
+ } ;
115
+ } , [ onPlaceSelected ] ) ; // Autofill workaround adapted from https://stackoverflow.com/questions/29931712/chrome-autofill-covers-autocomplete-for-google-maps-api-v3/49161445#49161445
103
116
104
117
( 0 , _react . useEffect ) ( function ( ) {
105
118
// TODO find out why react 18(strict mode) hangs the page loading
Original file line number Diff line number Diff line change @@ -94,6 +94,17 @@ export default function usePlacesWidget(props) {
94
94
return ( ) => ( event . current ? event . current . remove ( ) : undefined ) ;
95
95
} , [ ] ) ;
96
96
97
+ useEffect ( ( ) => {
98
+ if ( autocompleteRef . current && onPlaceSelected ) {
99
+ event . current = autocompleteRef . current . addListener ( "place_changed" , function ( ) {
100
+ if ( onPlaceSelected && autocompleteRef && autocompleteRef . current ) {
101
+ onPlaceSelected ( autocompleteRef . current . getPlace ( ) , inputRef . current , autocompleteRef . current ) ;
102
+ }
103
+ } ) ;
104
+ }
105
+ return ( ) => ( event . current ? event . current . remove ( ) : undefined ) ;
106
+ } , [ onPlaceSelected ] ) ;
107
+
97
108
// Autofill workaround adapted from https://stackoverflow.com/questions/29931712/chrome-autofill-covers-autocomplete-for-google-maps-api-v3/49161445#49161445
98
109
useEffect ( ( ) => {
99
110
// TODO find out why react 18(strict mode) hangs the page loading
You can’t perform that action at this time.
0 commit comments