From 75dd519ca7c4acde76c3f6241609c73592620460 Mon Sep 17 00:00:00 2001 From: Vivek JM <24496671+vivekjm@users.noreply.github.com> Date: Mon, 22 Jun 2026 12:06:43 +0530 Subject: [PATCH] fix: avoid disabled accessibility state for active chips --- src/components/Chip/Chip.tsx | 4 +++- src/components/__tests__/Chip.test.tsx | 18 ++++++++++++++++-- .../__tests__/__snapshots__/Chip.test.tsx.snap | 8 ++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/Chip/Chip.tsx b/src/components/Chip/Chip.tsx index c59d02fa6e..50ac00d6fe 100644 --- a/src/components/Chip/Chip.tsx +++ b/src/components/Chip/Chip.tsx @@ -214,6 +214,8 @@ const Chip = ({ onPressIn, onPressOut, }); + const touchableOnPress = + !disabled && !hasPassedTouchHandler ? () => {} : onPress; const isOutlined = mode === 'outlined'; @@ -306,7 +308,7 @@ const Chip = ({ borderless background={background} style={[{ borderRadius }, styles.touchable]} - onPress={onPress} + onPress={touchableOnPress} onLongPress={onLongPress} onPressIn={hasPassedTouchHandler ? handlePressIn : undefined} onPressOut={hasPassedTouchHandler ? handlePressOut : undefined} diff --git a/src/components/__tests__/Chip.test.tsx b/src/components/__tests__/Chip.test.tsx index 1c04130ebb..bfc7eec0df 100644 --- a/src/components/__tests__/Chip.test.tsx +++ b/src/components/__tests__/Chip.test.tsx @@ -60,9 +60,23 @@ it('renders selected chip', () => { expect(tree).toMatchSnapshot(); }); -it('renders disabled chip if there is no touch handler passed', () => { +it('does not mark chip disabled if there is no touch handler passed', () => { const { getByTestId } = render( - Disabled chip + Informational chip + ); + + expect( + getByTestId('informational-chip').props.accessibilityState + ).toMatchObject({ + disabled: false, + }); +}); + +it('marks chip disabled when disabled prop is passed', () => { + const { getByTestId } = render( + + Disabled chip + ); expect(getByTestId('disabled-chip').props.accessibilityState).toMatchObject({ diff --git a/src/components/__tests__/__snapshots__/Chip.test.tsx.snap b/src/components/__tests__/__snapshots__/Chip.test.tsx.snap index 736f79b6fe..2a6fbfe21b 100644 --- a/src/components/__tests__/__snapshots__/Chip.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Chip.test.tsx.snap @@ -46,7 +46,7 @@ exports[`renders chip with close button 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": true, + "disabled": false, "expanded": undefined, "selected": false, } @@ -344,7 +344,7 @@ exports[`renders chip with custom close button 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": true, + "disabled": false, "expanded": undefined, "selected": false, } @@ -642,7 +642,7 @@ exports[`renders chip with icon 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": true, + "disabled": false, "expanded": undefined, "selected": false, } @@ -1167,7 +1167,7 @@ exports[`renders selected chip 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": true, + "disabled": false, "expanded": undefined, "selected": true, }