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
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ describe('Chip', () => {
expect(driver.getIcon().exists()).toBeTruthy();
expect(driver.getDismissIcon().exists()).toBeTruthy();
});

describe('Accessibility', () => {
it('should set accessibilityState.selected when selected is true', () => {
const driver = getDriver({selected: true});
expect(driver.getElement().props.accessibilityState).toEqual({selected: true});
});

it('should set accessibilityState.selected when selected is false', () => {
const driver = getDriver({selected: false});
expect(driver.getElement().props.accessibilityState).toEqual({selected: false});
});

it('should not set accessibilityState when selected is not provided', () => {
const driver = getDriver();
expect(driver.getElement().props.accessibilityState).toBeUndefined();
});
});
});
6 changes: 6 additions & 0 deletions packages/react-native-ui-lib/src/components/chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export type ChipProps = ViewProps &
* On Chip press callback
*/
onPress?: (props: any) => void;
/**
* Indicates whether the chip is selected, exposed to screen readers via accessibilityState
*/
selected?: boolean;
/**
* Chip's background color
*/
Expand Down Expand Up @@ -158,6 +162,7 @@ const Chip = ({
labelStyle,
onPress,
resetSpacings,
selected,
size = DEFAULT_SIZE,
useSizeAsMinimum = true,
recorderTag,
Expand Down Expand Up @@ -332,6 +337,7 @@ const Chip = ({
style={[styles.container, {backgroundColor}, {borderRadius}, containerStyle, containerSizeStyle]}
testID={testID}
hitSlop={hitSlop}
accessibilityState={selected !== undefined ? {selected} : undefined}
{...others}
>
{avatarProps && renderAvatar()}
Expand Down
Loading