File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,20 @@ function usePlacesWidget(props) {
9999 return function ( ) {
100100 return event . current ? event . current . remove ( ) : undefined ;
101101 } ;
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
103116
104117 ( 0 , _react . useEffect ) ( function ( ) {
105118 // 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) {
9494 return ( ) => ( event . current ? event . current . remove ( ) : undefined ) ;
9595 } , [ ] ) ;
9696
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+
97108 // Autofill workaround adapted from https://stackoverflow.com/questions/29931712/chrome-autofill-covers-autocomplete-for-google-maps-api-v3/49161445#49161445
98109 useEffect ( ( ) => {
99110 // TODO find out why react 18(strict mode) hangs the page loading
You can’t perform that action at this time.
0 commit comments