mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
[MaterialButtonToggleGroup] SelectionRequired attribute doesn`t enforce checkedButtonId to be a valid id (returns -1)
Resolves https://github.com/material-components/material-components-android/issues/956 PiperOrigin-RevId: 292334820
This commit is contained in:
parent
6e340c49d4
commit
e56b141dd5
@ -702,6 +702,7 @@ public class MaterialButtonToggleGroup extends LinearLayout {
|
||||
if (selectionRequired && checkedButtonIds.isEmpty()) {
|
||||
// undo deselection
|
||||
setCheckedStateForView(childId, true);
|
||||
checkedId = childId;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -180,4 +180,21 @@ public class MaterialButtonToggleGroupTest {
|
||||
assertThat(((Checkable) first).isChecked()).isTrue();
|
||||
assertThat(((Checkable) second).isChecked()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void singleSelection_withSelectionRequired_correctCheckedIdWithTwoTaps() {
|
||||
toggleGroup.setSingleSelection(true);
|
||||
toggleGroup.setSelectionRequired(true);
|
||||
|
||||
View child = toggleGroup.getChildAt(1);
|
||||
int id = ViewCompat.generateViewId();
|
||||
child.setId(id);
|
||||
|
||||
child.performClick();
|
||||
child.performClick();
|
||||
|
||||
// child button is selected
|
||||
assertThat(toggleGroup.getCheckedButtonId()).isEqualTo(id);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user