Skip to content

Commit

Permalink
Allow Persistent Results (#705)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
haydncomley authored Mar 23, 2021
1 parent 1887f72 commit 2e3edf5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions GooglePlacesAutocomplete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ interface GooglePlacesAutocompleteProps {
listEmptyComponent?: JSX.Element | React.ComponentType<{}>;
listUnderlayColor?: string;
listViewDisplayed?: 'auto' | boolean;
keepResultsAfterBlur?: boolean;
minLength?: number; // minimum length of text to search
// Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
nearbyPlacesAPI?: 'GoogleReverseGeocoding' | 'GooglePlacesSearch';
Expand Down
6 changes: 5 additions & 1 deletion GooglePlacesAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ export const GooglePlacesAutocomplete = forwardRef((props, ref) => {
const _onBlur = (e) => {
if (e && isNewFocusInAutocompleteResultList(e)) return;

setListViewDisplayed(false);
if (!props.keepResultsAfterBlur) {
setListViewDisplayed(false);
}
inputRef?.current?.blur();
};

Expand Down Expand Up @@ -846,6 +848,7 @@ GooglePlacesAutocomplete.propTypes = {
listEmptyComponent: PropTypes.func,
listUnderlayColor: PropTypes.string,
listViewDisplayed: PropTypes.oneOf(['auto', PropTypes.bool]),
keepResultsAfterBlur: PropTypes.bool,
minLength: PropTypes.number,
nearbyPlacesAPI: PropTypes.string,
numberOfLines: PropTypes.number,
Expand Down Expand Up @@ -894,6 +897,7 @@ GooglePlacesAutocomplete.defaultProps = {
keyboardShouldPersistTaps: 'always',
listUnderlayColor: '#c8c7cc',
listViewDisplayed: 'auto',
keepResultsAfterBlur: false,
minLength: 0,
nearbyPlacesAPI: 'GooglePlacesSearch',
numberOfLines: 1,
Expand Down

0 comments on commit 2e3edf5

Please sign in to comment.