Skip to content

Commit ef0a4d1

Browse files
authored
feat: add accessibility Label props (#229)
1 parent e5b113a commit ef0a4d1

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

example/src/PickerExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function BasicPickerExample() {
1010
<Picker
1111
testID="basic-picker"
1212
selectedValue={value}
13-
onValueChange={(v) => setValue(v)}>
13+
onValueChange={(v) => setValue(v)}
14+
accessibilityLabel="Basic Picker Accessibility Label"
15+
>
1416
<Item label="hello" value="key0" />
1517
<Item label="world" value="key1" />
1618
</Picker>

js/Picker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ type PickerProps = $ReadOnly<{|
115115
* @platform android
116116
*/
117117
numberOfLines?: ?number,
118+
119+
/**
120+
* The string used for the accessibility label. Will be read once focused on the picker but not on change.
121+
*/
122+
accessibilityLabel?: ?string,
118123
|}>;
119124

120125
/**

js/__tests__/Picker.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import {Platform} from 'react-native';
33
import Picker from '../Picker';
44

@@ -7,5 +7,14 @@ describe('Picker', () => {
77
Platform.OS = 'ios';
88
expect(<Picker />).toMatchSnapshot();
99
});
10-
it('should render the Android native component', () => {});
10+
it('should render the Android native component', () => {
11+
Platform.OS = 'android';
12+
expect(<Picker />).toMatchSnapshot();
13+
});
14+
it('should render component with accessibility label', () => {
15+
Platform.OS = 'ios';
16+
expect(
17+
<Picker accessibilityLabel="Label for this picker" />,
18+
).toMatchSnapshot();
19+
});
1120
});

js/__tests__/__snapshots__/Picker.test.js.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Picker should render component with accessibility label 1`] = `
4+
<Picker
5+
accessibilityLabel="Label for this picker"
6+
mode="dialog"
7+
/>
8+
`;
9+
10+
exports[`Picker should render the Android native component 1`] = `
11+
<Picker
12+
mode="dialog"
13+
/>
14+
`;
15+
316
exports[`Picker should render the iOS native component 1`] = `
417
<Picker
518
mode="dialog"

typings/Picker.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ export interface PickerProps<T = ItemValue> extends ViewProps {
5454
testID?: string;
5555
/**
5656
* Color of arrow for spinner dropdown in hexadecimal format
57+
* @platform android
5758
*/
58-
dropdownIconColor?: string;
59+
dropdownIconColor?: string;
5960

6061
/**
6162
* On Android, used to truncate the text with an ellipsis after computing the text layout, including line wrapping,
6263
* such that the total number of lines does not exceed this number. Default is '1'
6364
* @platform android
6465
*/
65-
numberOfLines?: number;
66+
numberOfLines?: number;
67+
68+
/**
69+
* The string used for the accessibility label. Will be read once focused on the picker but not on change.
70+
*/
71+
accessibilityLabel?: string;
72+
6673
}
6774

6875
declare class Picker<T> extends React.Component<PickerProps<T>, {}> {

0 commit comments

Comments
 (0)