Skip to content

Commit

Permalink
[Chip][a11y] Make multi-selection Chips announced as Buttons
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 447993125
  • Loading branch information
paulfthomas authored and leticiarossi committed May 11, 2022
1 parent 3e6329b commit d4c2c95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/java/com/google/android/material/chip/Chip.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public class Chip extends AppCompatCheckBox

@Nullable private CharSequence accessibilityClassName;
private static final String BUTTON_ACCESSIBILITY_CLASS_NAME = "android.widget.Button";
private static final String COMPOUND_BUTTON_ACCESSIBILITY_CLASS_NAME =
"android.widget.CompoundButton";
private static final String RADIO_BUTTON_ACCESSIBILITY_CLASS_NAME =
"android.widget.RadioButton";
private static final String GENERIC_VIEW_ACCESSIBILITY_CLASS_NAME = "android.view.View";
Expand Down Expand Up @@ -2335,7 +2333,7 @@ public CharSequence getAccessibilityClassName() {
if (parent instanceof ChipGroup && ((ChipGroup) parent).isSingleSelection()) {
return RADIO_BUTTON_ACCESSIBILITY_CLASS_NAME;
} else {
return COMPOUND_BUTTON_ACCESSIBILITY_CLASS_NAME;
return BUTTON_ACCESSIBILITY_CLASS_NAME;
}
} else if (isClickable()) {
return BUTTON_ACCESSIBILITY_CLASS_NAME;
Expand Down
13 changes: 13 additions & 0 deletions lib/javatests/com/google/android/material/chip/ChipGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,17 @@ public void isNotSingleLine_initializesAccessibilityNodeInfo() {
assertEquals(1, itemInfo.getRowIndex());
assertTrue(itemInfo.isSelected());
}

@Test
public void getChipAccessibilityClassName_multipleChecked_buttonName() {
Chip chip = (Chip) chipgroup.getChildAt(0);
assertEquals("android.widget.Button", chip.getAccessibilityClassName().toString());
}

@Test
public void getChipAccessibilityClassName_singleChecked_radioButtonName() {
chipgroup.setSingleSelection(true);
Chip chip = (Chip) chipgroup.getChildAt(0);
assertEquals("android.widget.RadioButton", chip.getAccessibilityClassName().toString());
}
}
12 changes: 12 additions & 0 deletions lib/javatests/com/google/android/material/chip/ChipTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static com.google.android.material.internal.ViewUtils.dpToPx;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;

import android.content.Context;
import android.graphics.RectF;
Expand Down Expand Up @@ -225,4 +226,15 @@ public void testZeroChipCornerRadius() {
.isWithin(DELTA)
.of(0);
}

@Test
public void getChipAccessibilityClassName_clickable_buttonName() {
assertEquals("android.widget.Button", chip.getAccessibilityClassName().toString());
}

@Test
public void getChipAccessibilityClassName_nonClickable_viewName() {
chip.setClickable(false);
assertEquals("android.view.View", chip.getAccessibilityClassName().toString());
}
}

0 comments on commit d4c2c95

Please sign in to comment.