Skip to content

Commit 2351d55

Browse files
authored
Switch - fix accessibility (#3511)
* Switch - fix accessibility * fix tests
1 parent 7b1fac0 commit 2351d55

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

src/components/switch/__tests__/index.spec.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ describe('Switch', () => {
4747
expect(onValueChange).not.toHaveBeenCalled();
4848
});
4949

50-
it('Accessibility value should be true when checked', async () => {
51-
const driver = testCase(testID, {value: true});
52-
53-
expect(driver.getAccessibilityValue()).toBe(true);
54-
});
55-
5650
it('Accessibility value should be false when not checked', async () => {
5751
const driver = testCase(testID, {value: false});
5852

@@ -65,12 +59,6 @@ describe('Switch', () => {
6559
expect(driver.isChecked()).toBe(true);
6660
});
6761

68-
it('Accessibility value should be false when not checked', async () => {
69-
const driver = testCase(testID, {value: false});
70-
71-
expect(driver.getAccessibilityValue()).toBe(false);
72-
});
73-
7462
it('Should be disabled', async () => {
7563
const driver = testCase(testID, {disabled: true});
7664

src/components/switch/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,10 @@ class Switch extends Component<SwitchProps> {
8383
getAccessibilityProps() {
8484
const {disabled, value} = this.props;
8585

86-
8786
return {
8887
accessible: true,
8988
accessibilityRole: 'switch',
90-
accessibilityState: {
91-
disabled,
92-
checked: value ? 'checked' : 'unchecked'
93-
},
94-
accessibilityValue: {text: value ? '1' : '0'}
89+
accessibilityState: {disabled, checked: value}
9590
};
9691
}
9792

src/components/switch/switch.driver.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ export const SwitchDriver = (props: ComponentProps) => {
66
const driver = usePressableDriver(useComponentDriver(props));
77

88
const getStyle = () => driver.getElement().props.style as ViewStyle;
9-
const getAccessibilityValue = () => driver.getElement().props.accessibilityValue?.text === '1';
109
const isDisabled = () => driver.getElement().props.accessibilityState?.disabled === true;
11-
const isChecked = () => driver.getElement().props.accessibilityValue?.text === '1';
10+
const isChecked = () => driver.getElement().props.accessibilityState?.checked;
1211

13-
return {...driver, getStyle, getAccessibilityValue, isDisabled, isChecked};
12+
return {...driver, getStyle, isDisabled, isChecked};
1413
};

0 commit comments

Comments
 (0)