Skip to content

Commit

Permalink
Fix onPress issue caused by blur event
Browse files Browse the repository at this point in the history
  • Loading branch information
fdobre authored and bell-steven committed Dec 10, 2020
1 parent 5190c9e commit dd8f63e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions GooglePlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,24 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
);
};

const _onBlur = () => {
const isNewFocusInAutocompleteResultList = ({ relatedTarget, currentTarget }) => {
if (!relatedTarget) return false;

var node = relatedTarget.parentNode;

while (node) {
if (node.id === 'result-list-id') return true;
node = node.parentNode;
}

return false;
}

const _onBlur = (e) => {
if (e && isNewFocusInAutocompleteResultList(e)) return;

setListViewDisplayed(false);

inputRef?.current?.blur();
};

Expand Down Expand Up @@ -717,6 +733,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
) {
return (
<FlatList
nativeID="result-list-id"
scrollEnabled={!props.disableScroll}
style={[
props.suppressDefaultStyles ? {} : defaultStyles.listView,
Expand Down Expand Up @@ -786,8 +803,8 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
}
onBlur={
onBlur
? () => {
_onBlur();
? (e) => {
_onBlur(e);
onBlur();
}
: _onBlur
Expand Down

0 comments on commit dd8f63e

Please sign in to comment.