Skip to content

Commit

Permalink
Merge pull request #6345 from developvsn/fix-tabpressing-addressinput
Browse files Browse the repository at this point in the history
Fix : Pressing Tab button in AddressSearch inputs
  • Loading branch information
NikkiWines authored Nov 19, 2021
2 parents 1737897 + 7cc6588 commit 8293550
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/AddressSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const defaultProps = {
const AddressSearch = (props) => {
const googlePlacesRef = useRef();
const [displayListViewBorder, setDisplayListViewBorder] = useState(false);
const [isSelected, setIsSelected] = useState(true);
useEffect(() => {
if (!googlePlacesRef.current) {
return;
Expand Down Expand Up @@ -86,10 +87,17 @@ const AddressSearch = (props) => {
<GooglePlacesAutocomplete
ref={googlePlacesRef}
fetchDetails
onBlur={() => {
if (isSelected) {
return;
}
googlePlacesRef.current.setAddressText('');
}}
suppressDefaultStyles
enablePoweredByContainer={false}
onPress={(data, details) => {
saveLocationDetails(details);
setIsSelected(true);

// After we select an option, we set displayListViewBorder to false to prevent UI flickering
setDisplayListViewBorder(false);
Expand All @@ -109,8 +117,15 @@ const AddressSearch = (props) => {
label: props.label,
containerStyles: props.containerStyles,
errorText: props.errorText,
onKeyPress: (event) => {
if (event.key !== 'Tab' || isSelected) {
return;
}
googlePlacesRef.current.setAddressText('');
},
onChangeText: (text) => {
const isTextValid = !_.isEmpty(text) && _.isEqual(text, props.value);
setIsSelected(false);

// Ensure whether an address is selected already or has address value initialized.
if (!_.isEmpty(googlePlacesRef.current.getAddressText()) && !isTextValid) {
Expand Down

0 comments on commit 8293550

Please sign in to comment.