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

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

Aperta
#4,979 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Java
Stelle
17.4k
Fork
3.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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:

    <com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:layout_width="0dp"
        android:layout_gravity="fill_horizontal"
        android:layout_row="1"
        android:layout_column="1"
        android:hint="">

        <AutoCompleteTextView
            android:id="@+id/hdmiPort"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="none"
            android:text="(Select)"
            app:simpleItems="@array/hdmi_labels" />

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da MaterialAutoCompleteTextView.onKeyDown() e verifica come shouldShowPopup() gestisce ENTER, confrontandolo con il comportamento della classe base AutoCompleteTextView descritto nell’issue. Conferma che ENTER selezioni l’elemento evidenziato del menu a discesa e aggiorni il campo chiudendo il popup, senza compromettere il comportamento dell’icona finale quando il popup è chiuso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
mobile
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.