material-components / material-components/material-components-android

[MaterialAutoCompleteTextView] Enter key does not work to select item from dropdown list

Open
#4,979 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

In my application, I am using a MaterialAutoCompleteTextView as an exposed dropdown (to implement a Spinner-like behavior). This is running on a device that is mostly using keyboard navigation, but it also expected to work with touch input.

Using the keyboard, I can press ENTER when the field has to focus to show the dropdown list, and use the arrow keys to navigate in the list. However, pressing ENTER key on a selected item simply closes the popup without updating the value in the field.

Relevant layout snippet:
```


```

The target activity uses theme `Theme.Material3Expressive.Dark.NoActionBar`.

After some debugging, I figured that KEYCODE_ENTER down event is first processed by `MaterialAutoCompleteTextView.onKeyDown()`, whether the popup is showing or not. This uses `shouldShowPopup()` to determine whether the dropdown should be down, and this returns true for the ENTER key. This then translates into clicking the end icon of the `TextInputLayout` component. When the popup is showing, this corresponds to a simple dismiss of the popup; hence why the value is not updated.

I don't believe this is the natural expected behavior in this scenario, though. I expected the popup to be dismissed AND the value to be updated with the selected item. I think the root cause is the fact that the translation `ENTER-key -> end-icon-click` is performed in all cases, even if the popup is showing. If you only do this translation if the popup is not showing, then you get back the expected behavior (as implemented in base `AutoCompleteTextView` class).

**Android API version:** 36

**Material Library version:** 1.14.0-alpha07alpha07)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at MaterialAutoCompleteTextView.onKeyDown() and inspect how shouldShowPopup() handles ENTER, comparing it with the base AutoCompleteTextView behavior described in the issue. Confirm that ENTER selects the highlighted dropdown item and updates the field while dismissing the popup, without breaking the end-icon behavior when the popup is closed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.