Skip to content

Commit d06eed1

Browse files
imhappipaulfthomas
authored andcommitted
[Search][A11y] Allow keyboard navigation between searchbar and other components
PiperOrigin-RevId: 811869184
1 parent 00a64e2 commit d06eed1

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

catalog/java/io/material/catalog/search/res/layout/cat_search_recycler_fragment.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
android:layout_height="wrap_content"
4040
android:fitsSystemWindows="true"
4141
app:liftOnScroll="false"
42-
app:statusBarForeground="?attr/colorSurface">
42+
app:statusBarForeground="?attr/colorSurface"
43+
android:touchscreenBlocksFocus="false">
4344

4445
<com.google.android.material.search.SearchBar
4546
android:id="@+id/open_search_bar"

lib/java/com/google/android/material/search/SearchBar.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,9 @@ public boolean onDependentViewChanged(
10611061
if (!initialized && dependency instanceof AppBarLayout) {
10621062
initialized = true;
10631063
AppBarLayout appBarLayout = (AppBarLayout) dependency;
1064+
// Necessary to enable keyboard navigation across searchbar and other elements due to
1065+
// toolbar being a keyboard navigation cluster from API 26+
1066+
appBarLayout.setTouchscreenBlocksFocus(false);
10641067
setAppBarLayoutTransparent(appBarLayout);
10651068
}
10661069
return changed;

lib/java/com/google/android/material/search/res/values/styles.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@
6262
<item name="android:paddingStart">4dp</item>
6363
<item name="android:paddingEnd">4dp</item>
6464
<item name="android:minHeight">64dp</item>
65+
<item name="android:touchscreenBlocksFocus">false</item>
6566
</style>
6667

6768
<style name="Widget.Material3Expressive.Toolbar.AppBarWithSearch">
6869
<item name="buttonGravity">center_vertical</item>
6970
<item name="android:layout_marginEnd">0dp</item>
7071
<item name="layout_scrollFlags">scroll|snap|enterAlways</item>
7172
<item name="materialThemeOverlay">@style/ThemeOverlay.Material3.Search</item>
73+
<item name="android:touchscreenBlocksFocus">false</item>
7274
</style>
7375

7476
<style name="ThemeOverlay.Material3Expressive.AppBarWithSearch" parent="">
@@ -96,6 +98,9 @@
9698
<item name="materialThemeOverlay">@style/ThemeOverlay.Material3.Search</item>
9799
<item name="liftOnScroll">false</item>
98100
<item name="liftOnScrollColor">?attr/colorSurfaceContainerHighest</item>
101+
<!-- Necessary to enable keyboard navigation across searchbar and other elements due to toolbar
102+
being a keyboard navigation cluster from API 26+ -->
103+
<item name="android:touchscreenBlocksFocus">false</item>
99104

100105
<!-- On newer API levels, hide shadows while keeping elevation. -->
101106
<item name="android:outlineAmbientShadowColor" tools:targetApi="p">@android:color/transparent</item>

0 commit comments

Comments
 (0)