-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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:
<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)