Skip to content

Commit 2e3edf5

Browse files
authored
Allow Persistent Results (#705)
* Allow Persistent Results - Results from the search can be made to persist after the blur event has been fired and focus from the input is lost.
1 parent 1887f72 commit 2e3edf5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

GooglePlacesAutocomplete.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ interface GooglePlacesAutocompleteProps {
395395
listEmptyComponent?: JSX.Element | React.ComponentType<{}>;
396396
listUnderlayColor?: string;
397397
listViewDisplayed?: 'auto' | boolean;
398+
keepResultsAfterBlur?: boolean;
398399
minLength?: number; // minimum length of text to search
399400
// Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
400401
nearbyPlacesAPI?: 'GoogleReverseGeocoding' | 'GooglePlacesSearch';

GooglePlacesAutocomplete.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
665665
const _onBlur = (e) => {
666666
if (e && isNewFocusInAutocompleteResultList(e)) return;
667667

668-
setListViewDisplayed(false);
668+
if (!props.keepResultsAfterBlur) {
669+
setListViewDisplayed(false);
670+
}
669671
inputRef?.current?.blur();
670672
};
671673

@@ -846,6 +848,7 @@ GooglePlacesAutocomplete.propTypes = {
846848
listEmptyComponent: PropTypes.func,
847849
listUnderlayColor: PropTypes.string,
848850
listViewDisplayed: PropTypes.oneOf(['auto', PropTypes.bool]),
851+
keepResultsAfterBlur: PropTypes.bool,
849852
minLength: PropTypes.number,
850853
nearbyPlacesAPI: PropTypes.string,
851854
numberOfLines: PropTypes.number,
@@ -894,6 +897,7 @@ GooglePlacesAutocomplete.defaultProps = {
894897
keyboardShouldPersistTaps: 'always',
895898
listUnderlayColor: '#c8c7cc',
896899
listViewDisplayed: 'auto',
900+
keepResultsAfterBlur: false,
897901
minLength: 0,
898902
nearbyPlacesAPI: 'GooglePlacesSearch',
899903
numberOfLines: 1,

0 commit comments

Comments
 (0)