Skip to content

Commit 644d141

Browse files
Material Design Teamhunterstich
authored andcommitted
[ExposedDropdownMenu] Dismiss modal popup in dismissDropDown
PiperOrigin-RevId: 484502383
1 parent 4a24684 commit 644d141

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/java/com/google/android/material/textfield/MaterialAutoCompleteTextView.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,36 @@ public void onItemClick(AdapterView<?> parent, View selectedView, int position,
174174

175175
@Override
176176
public void showDropDown() {
177-
if (accessibilityManager != null && accessibilityManager.isTouchExplorationEnabled()) {
177+
if (isTouchExplorationEnabled()) {
178178
modalListPopup.show();
179179
} else {
180180
super.showDropDown();
181181
}
182182
}
183183

184+
@Override
185+
public void dismissDropDown() {
186+
if (isTouchExplorationEnabled()) {
187+
modalListPopup.dismiss();
188+
} else {
189+
super.dismissDropDown();
190+
}
191+
}
192+
193+
@Override
194+
public void onWindowFocusChanged(boolean hasWindowFocus) {
195+
if (isTouchExplorationEnabled()) {
196+
// Do not dismissDropDown if touch exploration is enabled, in case the window lost focus
197+
// in favor of the modalListPopup.
198+
return;
199+
}
200+
super.onWindowFocusChanged(hasWindowFocus);
201+
}
202+
203+
private boolean isTouchExplorationEnabled() {
204+
return accessibilityManager != null && accessibilityManager.isTouchExplorationEnabled();
205+
}
206+
184207
@Override
185208
public <T extends ListAdapter & Filterable> void setAdapter(@Nullable T adapter) {
186209
super.setAdapter(adapter);
@@ -315,6 +338,12 @@ protected void onAttachedToWindow() {
315338
}
316339
}
317340

341+
@Override
342+
protected void onDetachedFromWindow() {
343+
super.onDetachedFromWindow();
344+
modalListPopup.dismiss();
345+
}
346+
318347
@Nullable
319348
@Override
320349
public CharSequence getHint() {

0 commit comments

Comments
 (0)