Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query & Show Suggestions on Focus #335

Open
ahilke opened this issue Aug 7, 2023 · 0 comments
Open

Query & Show Suggestions on Focus #335

ahilke opened this issue Aug 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ahilke
Copy link

ahilke commented Aug 7, 2023

Problem

I want to show the menu with place suggestions already when the input is focussed, not just after the user typed something. I tried using defaultOptions: true as part of selectProps, which is almost what I want. However, it only works with the initial value and does not update the suggestions when the input is blurred and focussed again.

I am using the component as a controlled input, something like this:

const GooglePlacesAutocompleteContainer = () => {
  const [value, setValue] = useState('Paris');

  return (
    <GooglePlacesAutocomplete
      selectProps={{
        defaultOptions: true,
        inputValue: value,
        onInputChange: (newValue, meta) => {
          if (meta.action === 'input-change') {
            setValue(newValue);
          }
        },
      }}
    />
  );
};

The behaviour is as follows:

  1. Input mounts with value "Paris".
  2. On focus, suggestions for "Paris" are shown.
  3. Type "London", suggestions for "London" are shown.
  4. Blur the input - input value stays "London" and menu closes.
  5. Focus input again - suggestions for "Paris" are shown, but input value is "London". I would like to show suggestions for "London" instead.

I hope I didn't miss anything, but I tried quite a few combinations of props without any success.

Suggestions

I found this issue with a suggested solution in react-select, which pretty much describes my use case: JedWatson/react-select#1525 (comment). However, I was not able to utilise this approach because I do not have access to the loadOptions function that is used by react-google-places-autocomplete. So an option could be to make this available as part of the library.

Alternatively, maybe there could be an option added to the GooglePlacesAutocomplete component, which would obviously more convenient.

@Tintef Tintef added the enhancement New feature or request label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants