Skip to content

Commit d7645ae

Browse files
Material Design Teamhunterstich
authored andcommitted
[Snackbar] Add an accessibility pane title of "Alert"
PiperOrigin-RevId: 655638807
1 parent e1a103e commit d7645ae

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ protected BaseTransientBottomBar(
388388

389389
view.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
390390
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
391+
ViewCompat.setAccessibilityPaneTitle(
392+
view, getContext().getString(R.string.snackbar_accessibility_pane_title));
391393

392394
// Make sure that we fit system windows and have a listener to apply any insets
393395
view.setFitsSystemWindows(true);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2024 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<resources xmlns:tools="http://schemas.android.com/tools">
18+
<!-- An accessibility pane title for a Snackbar. [CHAR LIMIT=NONE] -->
19+
<string name="snackbar_accessibility_pane_title">Alert</string>
20+
</resources>

tests/javatests/com/google/android/material/snackbar/SnackbarTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static com.google.android.material.testutils.TestUtilsActions.setLayoutDirection;
3030
import static org.hamcrest.Matchers.not;
3131
import static org.hamcrest.core.AllOf.allOf;
32+
import static org.junit.Assert.assertEquals;
3233
import static org.junit.Assert.assertFalse;
3334
import static org.junit.Assert.assertTrue;
3435
import static org.mockito.ArgumentMatchers.any;
@@ -399,6 +400,16 @@ public void testMultipleCallbacksWithRemoval() throws Throwable {
399400
.onDismissed(snackbar, BaseTransientBottomBar.BaseCallback.DISMISS_EVENT_MANUAL);
400401
}
401402

403+
@Test
404+
public void testAccessibilityPaneTitle() throws Throwable {
405+
final Snackbar snackbar =
406+
Snackbar.make(coordinatorLayout, MESSAGE_TEXT, Snackbar.LENGTH_INDEFINITE)
407+
.setAction(ACTION_TEXT, mock(View.OnClickListener.class));
408+
assertEquals(
409+
snackbar.getContext().getString(R.string.snackbar_accessibility_pane_title),
410+
ViewCompat.getAccessibilityPaneTitle(snackbar.getView()).toString());
411+
}
412+
402413
@Test
403414
public void testDefaultContext_usesAppCompat() throws Throwable {
404415
final Snackbar snackbar =

0 commit comments

Comments
 (0)