Skip to content

useAutocomplete highlight is not working correctly when options are already selected #44640

@vmichailidisdev

Description

@vmichailidisdev

Steps to reproduce

Steps:

  1. Open this link to live example: useAutocomplete highlight problem example.
  2. Follow the descriptions below for each issue.
  3. You may need to refresh the stackblitz inner iframe when the dependencies are loaded.

Current behavior

  • when multiple option is enabled:
    • when autoHighlight is disabled:
      • when we use value or defaultValue (have some options selected by default)
        • Issue 1:
          1. focus the input.
          2. use the arrow down button.
            Notice that the highlight starts below the last selected option.
        • Issue 2:
          1. focus the input.
          2. press Enter.
            Notice that the last selected value is unselected.
    • when autoHighlight is enabled:
      • when we use value or defaultValue (have some options selected by default)
        1. focus the input
          Notice that the highlighted option in the last selected option.

Expected behavior

  • when multiple option is enabled:
    • when autoHighlight is disabled:
      • when we use value or defaultValue (have some options selected by default)
        • Issue 1:
          1. focus the input.
          2. use the arrow down button.
            The highlight should start from the first option (index 0).
        • Issue 2:
          1. focus the input.
          2. press Enter.
            Enter should do nothing (noop) because nothing should be highlighted in that moment.
    • when autoHighlight is enabled:
      • when we use value or defaultValue (have some options selected by default)
        1. focus the input
          The highlighted should be the first option (index 0).

Context

I am trying to build a very complex component using useAutocomplete that is out of context of this issue. I am demonstrating the issue with the example of the useAutocomplete from mui documentation https://mui.com/material-ui/react-autocomplete/#customized-hook.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: useAutocomplete, autocomplete, highlight

Search keywords:

Metadata

Metadata

Assignees

Labels

scope: autocompleteChanges related to the autocomplete. This includes ComboBox.type: expected behaviorThe current behavior is already the one expected.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions