Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions GooglePlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
const [url] = useState(getRequestUrl(props.requestUrl));

const inputRef = useRef();
const containerRef = useRef();

useEffect(() => {
if (Platform.OS !== 'web' || !listViewDisplayed) {
return;
}

// This will close search results list when user clicks outside the container
Comment thread
NikkiWines marked this conversation as resolved.
Resolved
const outsideClickHandler = (e) => {
if (containerRef.current?.contains(e.target)) {
return;
}
setListViewDisplayed(false);
};

document.addEventListener('mousedown', outsideClickHandler);

return () => document.removeEventListener('mousedown', outsideClickHandler);
}, [listViewDisplayed]);

useEffect(() => {
// This will load the default value's search results after the view has
Expand Down Expand Up @@ -623,12 +642,14 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
horizontal={true}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
focusable={false}
>
<TouchableHighlight
style={
props.isRowScrollable ? { minWidth: '100%' } : { width: '100%' }
}
onPress={() => _onPress(rowData)}
onBlur={_onBlur}
underlayColor={props.listUnderlayColor || '#c8c7cc'}
>
<View
Expand Down Expand Up @@ -799,6 +820,7 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
props.suppressDefaultStyles ? {} : defaultStyles.container,
props.styles.container,
]}
ref={containerRef}
pointerEvents='box-none'
>
{!props.textInputHide && (
Expand Down