Skip to content

Commit 858fa6a

Browse files
ikim24dsn5ft
authored andcommitted
Update Chip's close icon Drawable to respect both the chip state (includes state_focused when focusing on the chip) and close icon state (includes state_focused when focusing on the close icon).
PiperOrigin-RevId: 260507798
1 parent 3f73804 commit 858fa6a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/java/com/google/android/material/chip/ChipDrawable.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,15 @@ private boolean onStateChange(int[] chipState, int[] closeIconState) {
10551055
invalidate |= checkedIcon.setState(chipState);
10561056
}
10571057
if (isStateful(closeIcon)) {
1058-
invalidate |= closeIcon.setState(closeIconState);
1058+
// Merge the chipState and closeIconState so that when the Chip is pressed, focused, or
1059+
// hovered, the close icon acts like it is pressed, focused, or hovered. Do not use the merged
1060+
// state for the closeIconRipple as that should only behave pressed, focused, or hovered when
1061+
// the closeIcon is pressed, focused, or hovered.
1062+
int[] closeIconMergedState = new int[chipState.length + closeIconState.length];
1063+
System.arraycopy(chipState, 0, closeIconMergedState, 0, chipState.length);
1064+
System.arraycopy(
1065+
closeIconState, 0, closeIconMergedState, chipState.length, closeIconState.length);
1066+
invalidate |= closeIcon.setState(closeIconMergedState);
10591067
}
10601068
//noinspection NewApi
10611069
if (RippleUtils.USE_FRAMEWORK_RIPPLE && isStateful(closeIconRipple)) {

0 commit comments

Comments
 (0)