The selection is not maintained, only if I add code inside onPlaceSelected
nappalm opened this issue · comments
Manuel Morales commented
Because my current code does not work, however if I use only a console.log within onPlaceSelected the selection in the input is maintained correctly.
<Controller
name="location"
render={({ field, fieldState: { error } }) => {
return (
<div>
<span style={{ color: 'black' }}>Location</span>
<Input
fullWidth
inputComponent={({ inputRef, onFocus, onBlur, ...props }) => (
<Autocomplete
apiKey="..."
{...props}
onPlaceSelected={(selected) => {
const lat = selected.geometry.location.lat();
const lng = selected.geometry.location.lng();
field.onChange({
lat,
lng,
formatted_address: selected.formatted_address,
});
}}
/>
)}
/>
</div>
);
}}
/>
Stefan Bauckmeier commented
First idea: did you checked if your Input
or Controller
component is rerendered for some reason, so it resets the value?