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

[Autocomplete] Autohighlight does not work properly with repeated options #45279

Open
acai777 opened this issue Feb 10, 2025 · 1 comment
Open
Assignees
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@acai777
Copy link

acai777 commented Feb 10, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/quizzical-dewdney-wv3jzg
  2. Search for the term pediatric - notice how the autohighlight is NOT on the first dropdown item. However, if we press enter, we will still correctly select the first dropdown item (pediatrician)
  3. Delete the last letter c so that we have the term pediatri - notice how the autohighlight is now on pediatrician, the third term. If we press enter, we correctly select the first dropdown item, pediatric ent.

Current behavior

autohighlight styling is not always on the first dropdown item if the previous first row item is on the most recent batch of dropdown options and is in a different row/order. See steps to recreate this behavior.

CleanShot.2025-02-10.at.12.48.38.mp4

Expected behavior

autohighlight styling should always initially be on the first dropdown item

Context

I am using MUI's autocomplete for a specific use case. I do not filter down the results the more you type. Instead, I might return different results, or the same results but in a different order.

In this example, I simulate the bug that I am seeing in my application. You will notice that the autohighlight attribute does not work properly when the next batch of options contains the previous first row's option; we highlight the previous first dropdown item when we should highlight the new first option. However, if the user presses Enter, the component still correctly selects the first row (assuming the user hasn't manually highlighted some other row).

Is there a fix for this, or a workaround I am missing? I have searched past issues and it seems like something similar has come up (but no potential fixes).

Your environment

I am using version 5 (see package.json).

Search keywords: Autocomplete, autohighlight

@acai777 acai777 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 10, 2025
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Feb 11, 2025
@aarongarciah aarongarciah added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 11, 2025
@aarongarciah
Copy link
Member

Looks like a bug. @mj12albert can you take a look?

@aarongarciah aarongarciah changed the title Autocomplete's autohighlight does not work properly with repeated options [Autocomplete] Autohighlight does not work properly with repeated options Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants