Skip to content

Commit 753eae0

Browse files
committed
feat: add accessibilityLabel to support Android Appium
- Added `accessibilityLabel` prop in components that declare the `testID` prob. It's value defaults to `testID` if given null. This aims to fix Appium issue with Android testID.
1 parent ee3ffbb commit 753eae0

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed

examples/default/src/components/InputField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const InputField = forwardRef<TextInput, InputFieldProps>(
4949
style={[styles.textInput, style]}
5050
maxLength={maxLength}
5151
accessible={true}
52-
accessibilityLabel={accessibilityLabel}
52+
accessibilityLabel={accessibilityLabel ?? testID}
5353
keyboardType={keyboardType}
5454
value={value}
5555
testID={testID}

examples/default/src/components/ListTile.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ interface ListTileProps extends PropsWithChildren {
88
onPress?: () => void;
99
testID?: string;
1010
truncateSubtitle?: boolean;
11-
testID?: string;
11+
accessibilityLabel?: string;
1212
}
1313

1414
export const ListTile: React.FC<ListTileProps> = ({ title,
1515
subtitle,
1616
onPress,
1717
children,
1818
testID,
19-
truncateSubtitle = false, }) => {
19+
truncateSubtitle = false,
20+
accessibilityLabel, }) => {
2021
return (
2122
<Pressable
2223
onPress={onPress}
2324
p="4"
2425
rounded="2"
2526
testID={testID}
27+
accessibilityLabel={accessibilityLabel ?? testID}
2628
shadow="1"
2729
accessible={true}
2830
borderBottomWidth="1"

examples/default/src/components/PlatformListTile.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface PlatformListTileProps extends PropsWithChildren {
88
onPress?: () => void;
99
platform?: 'ios' | 'android';
1010
testID?: string;
11+
accessibilityLabel?: string;
1112
}
1213

1314
export const PlatformListTile: React.FC<PlatformListTileProps> = ({
@@ -16,6 +17,7 @@ export const PlatformListTile: React.FC<PlatformListTileProps> = ({
1617
platform,
1718
children,
1819
testID,
20+
accessibilityLabel,
1921
}) => {
2022
if (Platform.OS === platform || !platform) {
2123
return (
@@ -28,7 +30,8 @@ export const PlatformListTile: React.FC<PlatformListTileProps> = ({
2830
borderColor="coolGray.300"
2931
bg="coolGray.100"
3032
_pressed={{ bg: 'coolGray.200' }}
31-
testID={testID}>
33+
testID={testID}
34+
accessibilityLabel={accessibilityLabel ?? testID}>
3235
<HStack justifyContent="space-between" alignItems="center">
3336
<Text>{title}</Text>
3437
<Box width={160}>{children}</Box>

examples/default/src/components/Select.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ interface SelectItem<T> {
77
value: T;
88
isInitial?: boolean;
99
testID?: string;
10+
accessibilityLabel?: string;
1011
}
1112

1213
interface SelectProps<T> {
1314
label: string;
1415
items: SelectItem<T>[];
1516
onValueChange: (value: T) => void;
1617
testID?: string;
18+
accessibilityLabel?: string;
1719
}
1820

19-
export function Select<T>({ label, items, onValueChange, testID }: SelectProps<T>) {
21+
export function Select<T>({ label, items, onValueChange, testID, accessibilityLabel }: SelectProps<T>) {
2022
const initialItem = items.find((i) => i.isInitial) ?? items[0];
2123
const [selectedItem, setSelectedItem] = useState(initialItem);
2224

2325
return (
2426
<NativeBaseSelect
2527
height="10"
2628
placeholder={label}
27-
accessibilityLabel={label}
29+
accessibilityLabel={accessibilityLabel ?? testID}
2830
selectedValue={selectedItem.label}
2931
onValueChange={(value) => {
3032
const item = items.find((i) => i.label === value)!;

examples/default/src/screens/apm/FlowsScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const FlowsScreen: React.FC = () => {
4040
placeholder="Flow Name"
4141
onChangeText={(text) => setFlowName(text)}
4242
value={flowName}
43+
testID="id_flow_name"
4344
/>
4445
<CustomButton title="Start Flow" onPress={startFlow} />
4546
<CustomButton title="Start 5s Delayed Flow" onPress={startDelayedFlow} />

examples/default/src/screens/bug-reporting/DisclaimerTextScreen.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ export const DisclaimerTextScreen: React.FC<
3131
onChangeText={setLocalText}
3232
value={localText}
3333
testID="id_disclaimer_input"
34+
accessibilityLabel="id_disclaimer_input"
3435
multiline={true}
3536
/>
36-
<Button onPress={handleSave} testID="id_disclaimer_save">
37+
<Button onPress={handleSave} testID="id_disclaimer_save" accessibilityLabel="id_disclaimer_save">
3738
Save
3839
</Button>
39-
<Button colorScheme="danger" onPress={() => setLocalText('')} testID="id_disclaimer_clear">
40+
<Button colorScheme="danger" onPress={() => setLocalText('')} testID="id_disclaimer_clear" accessibilityLabel="id_disclaimer_clear">
4041
Clear
4142
</Button>
4243
</VStack>

examples/default/src/screens/bug-reporting/UserConsentScreen.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const UserConsentScreen: React.FC<
5050
onChangeText={setKey}
5151
value={key}
5252
testID="id_consent_key"
53+
accessibilityLabel="id_consent_key"
5354
/>
5455
</View>
5556
<View style={styles.inputWrapper}>
@@ -59,6 +60,7 @@ export const UserConsentScreen: React.FC<
5960
onChangeText={setDescription}
6061
value={description}
6162
testID="id_consent_description"
63+
accessibilityLabel="id_consent_description"
6264
/>
6365
</View>
6466
<View style={styles.inputWrapper}>
@@ -134,7 +136,7 @@ export const UserConsentScreen: React.FC<
134136
onValueChange={setActionType}
135137
/>
136138
</View>
137-
<Button mt="4" onPress={handleSubmit} testID="id_submit_consent">
139+
<Button mt="4" onPress={handleSubmit} testID="id_submit_consent" accessibilityLabel="id_submit_consent">
138140
Add User Consent
139141
</Button>
140142
</VStack>

0 commit comments

Comments
 (0)