Skip to content

Commit

Permalink
fix: unified behavior when focusing on CheckBox.Item with screen read…
Browse files Browse the repository at this point in the history
…er (#2921)
  • Loading branch information
grgr-dkrk authored Nov 2, 2021
1 parent 5c8544f commit 5faa1ec
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/Checkbox/CheckboxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,20 @@ const CheckboxItem = ({
}

return (
<TouchableRipple onPress={onPress} testID={testID}>
<View style={[styles.container, style]} pointerEvents="none">
<TouchableRipple
accessibilityLabel={label}
accessibilityRole="checkbox"
accessibilityState={{
checked: status === 'checked',
}}
onPress={onPress}
testID={testID}
>
<View
style={[styles.container, style]}
pointerEvents="none"
importantForAccessibility="no-hide-descendants"
>
{isLeading && checkbox}
<Text
style={[
Expand Down
28 changes: 28 additions & 0 deletions src/components/__tests__/Checkbox/CheckboxItem.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Platform } from 'react-native';
import renderer from 'react-test-renderer';
import { render } from 'react-native-testing-library';
import Checkbox from '../../Checkbox';

it('renders unchecked', () => {
Expand Down Expand Up @@ -47,3 +48,30 @@ it('can render leading checkbox control', () => {
.toJSON();
expect(tree).toMatchSnapshot();
});

it('should have `accessibilityState={ checked: true }` when `status="checked"`', () => {
const { getByA11yState } = render(
<Checkbox.Item status="checked" label="Checked Button" />
);

const element = getByA11yState({ checked: true });
expect(element).toBeTruthy();
});

it('should have `accessibilityState={ checked: false }` when `status="unchecked"', () => {
const { getByA11yState } = render(
<Checkbox.Item status="unchecked" label="Unchecked Button" />
);

const element = getByA11yState({ checked: false });
expect(element).toBeTruthy();
});

it('should have `accessibilityState={ checked: false }` when `status="indeterminate"', () => {
const { getByA11yState } = render(
<Checkbox.Item status="indeterminate" label="Indeterminate Button" />
);

const element = getByA11yState({ checked: false });
expect(element).toBeTruthy();
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

exports[`can render leading checkbox control 1`] = `
<View
accessibilityLabel="Default with leading control"
accessibilityRole="checkbox"
accessibilityState={
Object {
"checked": false,
}
}
accessible={true}
focusable={false}
onClick={[Function]}
Expand All @@ -19,6 +26,7 @@ exports[`can render leading checkbox control 1`] = `
}
>
<View
importantForAccessibility="no-hide-descendants"
pointerEvents="none"
style={
Array [
Expand Down Expand Up @@ -142,6 +150,13 @@ exports[`can render leading checkbox control 1`] = `

exports[`can render the Android checkbox on different platforms 1`] = `
<View
accessibilityLabel="iOS Checkbox"
accessibilityRole="checkbox"
accessibilityState={
Object {
"checked": false,
}
}
accessible={true}
focusable={false}
onClick={[Function]}
Expand All @@ -159,6 +174,7 @@ exports[`can render the Android checkbox on different platforms 1`] = `
}
>
<View
importantForAccessibility="no-hide-descendants"
pointerEvents="none"
style={
Array [
Expand Down Expand Up @@ -316,6 +332,13 @@ exports[`can render the Android checkbox on different platforms 1`] = `

exports[`can render the iOS checkbox on different platforms 1`] = `
<View
accessibilityLabel="iOS Checkbox"
accessibilityRole="checkbox"
accessibilityState={
Object {
"checked": false,
}
}
accessible={true}
focusable={false}
onClick={[Function]}
Expand All @@ -333,6 +356,7 @@ exports[`can render the iOS checkbox on different platforms 1`] = `
}
>
<View
importantForAccessibility="no-hide-descendants"
pointerEvents="none"
style={
Array [
Expand Down Expand Up @@ -456,6 +480,13 @@ exports[`can render the iOS checkbox on different platforms 1`] = `

exports[`renders unchecked 1`] = `
<View
accessibilityLabel="Unchecked Button"
accessibilityRole="checkbox"
accessibilityState={
Object {
"checked": false,
}
}
accessible={true}
focusable={false}
onClick={[Function]}
Expand All @@ -473,6 +504,7 @@ exports[`renders unchecked 1`] = `
}
>
<View
importantForAccessibility="no-hide-descendants"
pointerEvents="none"
style={
Array [
Expand Down

0 comments on commit 5faa1ec

Please sign in to comment.