Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ const Chip = ({
onPressIn,
onPressOut,
});
const touchableOnPress =
!disabled && !hasPassedTouchHandler ? () => {} : onPress;

const isOutlined = mode === 'outlined';

Expand Down Expand Up @@ -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}
Expand Down
18 changes: 16 additions & 2 deletions src/components/__tests__/Chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Chip testID="disabled-chip">Disabled chip</Chip>
<Chip testID="informational-chip">Informational chip</Chip>
);

expect(
getByTestId('informational-chip').props.accessibilityState
).toMatchObject({
disabled: false,
});
});

it('marks chip disabled when disabled prop is passed', () => {
const { getByTestId } = render(
<Chip disabled testID="disabled-chip">
Disabled chip
</Chip>
);

expect(getByTestId('disabled-chip').props.accessibilityState).toMatchObject({
Expand Down
8 changes: 4 additions & 4 deletions src/components/__tests__/__snapshots__/Chip.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports[`renders chip with close button 1`] = `
{
"busy": undefined,
"checked": undefined,
"disabled": true,
"disabled": false,
"expanded": undefined,
"selected": false,
}
Expand Down Expand Up @@ -344,7 +344,7 @@ exports[`renders chip with custom close button 1`] = `
{
"busy": undefined,
"checked": undefined,
"disabled": true,
"disabled": false,
"expanded": undefined,
"selected": false,
}
Expand Down Expand Up @@ -642,7 +642,7 @@ exports[`renders chip with icon 1`] = `
{
"busy": undefined,
"checked": undefined,
"disabled": true,
"disabled": false,
"expanded": undefined,
"selected": false,
}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ exports[`renders selected chip 1`] = `
{
"busy": undefined,
"checked": undefined,
"disabled": true,
"disabled": false,
"expanded": undefined,
"selected": true,
}
Expand Down