Material-ui: Autocomplete is not showing options even though they exist

Created on 21 Jul 2020  路  6Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

Autocomplete does not always display options even if they are available.

Expected Behavior 馃

Display all options if available.

Steps to Reproduce 馃暪

Steps:

  1. visit codesandbox.
  2. Type "s" and options are displayed.
  3. Type "sc" and options are not displayed.
  4. type "columbia, s" and options are not displayed

Context 馃敠

The API is being mocked in the codesandbox with 4 options: "s", "sc", "columbia, s" and "columbia, sc." In my environment it is a remote API call. The issue is consistent with queries to matches (or lack there of) but there doesn't seem to be any reason for which are displayed and which aren't, so far as I can tell.

(Also, sorry about the TypeScript noise in the codesandbox.)

Screen Shot 2020-07-21 at 1 37 26 AM

Screen Shot 2020-07-20 at 11 47 25 PM

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.11.0 |
| React | v16.13.1 |
| Browser | Chrome v84.0.4147.89 |
| TypeScript | v3.7.5 |
| Material-UI/lab | ^4.0.0-alpha.55 |

As an aside, thank you guys for the awesome library!

Autocomplete docs good first issue

Most helpful comment

@chanced Thanks for raising this issue. There is a learning gap that we need to fill. What do you think of this diff?

diff --git a/docs/src/pages/components/autocomplete/autocomplete.md b/docs/src/pages/components/autocomplete/autocomplete.md
index ff215c962a..2f5b8fe6b7 100644
--- a/docs/src/pages/components/autocomplete/autocomplete.md
+++ b/docs/src/pages/components/autocomplete/autocomplete.md
@@ -101,6 +101,12 @@ Head to the [customization](#customization) section for an example with the `Aut

 {{"demo": "pages/components/autocomplete/Asynchronous.js"}}

+If the logic is fetching new options at each keystroke,
+using the current value of the textbox to filter on the server,
+you need to disable the built-in filtering of the autocomplete component:
+
+```jsx
+<Autocomplete filterOptions={(x) => x} />
+```
+
 ### Google Maps place

 A customized UI for Google Maps Places Autocomplete.

Do you want to work on a pull request? :)

All 6 comments

@chanced Thanks for raising this issue. There is a learning gap that we need to fill. What do you think of this diff?

diff --git a/docs/src/pages/components/autocomplete/autocomplete.md b/docs/src/pages/components/autocomplete/autocomplete.md
index ff215c962a..2f5b8fe6b7 100644
--- a/docs/src/pages/components/autocomplete/autocomplete.md
+++ b/docs/src/pages/components/autocomplete/autocomplete.md
@@ -101,6 +101,12 @@ Head to the [customization](#customization) section for an example with the `Aut

 {{"demo": "pages/components/autocomplete/Asynchronous.js"}}

+If the logic is fetching new options at each keystroke,
+using the current value of the textbox to filter on the server,
+you need to disable the built-in filtering of the autocomplete component:
+
+```jsx
+<Autocomplete filterOptions={(x) => x} />
+```
+
 ### Google Maps place

 A customized UI for Google Maps Places Autocomplete.

Do you want to work on a pull request? :)

@oliviertassinari thanks! That fixed my issue and that documentation looks good.

Would a warning help? If so, I can look into putting one together and issuing a pull request. Maybe an equality check on options and warn if in dev and filterOptions is not set?

For a warning, I don't see how it could work without false positives. Docs would already be great.

@oliviertassinari ah, fair enough. I was thinking that a ref equality check in comparison to lack of results may work but you're right.

did you just want a pull req of what you wrote? Not sure what I'd work on in terms of a pull request then.

did you just want a pull req of what you wrote? Not sure what I'd work on in terms of a pull request then.

It's a proposal solution. If this would have solved your problem, I think that we should apply it. Do you confirm or infirm?

@oliviertassinari I definitely confirm. It solved my problem, for sure.

Sorry for my confusion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sys13 picture sys13  路  3Comments

zabojad picture zabojad  路  3Comments

ghost picture ghost  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments

rbozan picture rbozan  路  3Comments