I’d like to add an accessibilityIdentifier
to a React Native component, so that I can use Xcode’s UI testing to navigate around my app.
Is there a way to specify the accessibilityIdentifier
(not the accessibilityLabel
) for React Native?
On Android, accessible={true} property for a react-native View will be translated into native focusable={true} . In the above example, we can't get accessibility focus separately on 'text one' and 'text two'. Instead we get focus on a parent view with 'accessible' property.
To test the accessibility of a React Native application, open Xcode and go to Open Developer Tool — Accessibility Inspector. After clicking the icon, search for your emulator window and select the desired component to inspect its accessibility props.
Accessibility ID As Accessibility ID can be used for cross-platform automation, the code becomes reusable. For iOS, the default Accessibility ID is set to the name of the UI element. For Android, the value of Accessibility is same as the value of the attribute “content-desc”.
On Android, accessible={true} property for a react-native View will be translated into native focusable={true}. accessibilityHint An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not clear from the accessibility label.
You can add an accessibilityIdentifier
on React Native components (View, Text, Image...) using the testID property. This gets added to the component as a accessibilityIdentifier
on iOS.
Note that it doesn't work on custom components.
Here's an example:
<TextInput
placeholderTextColor="#dddddd"
style={[styles.main, styles.textColor]}
placeholder="Add a new todo item"
onChangeText={this.handleInputChanges}
value={inputValue}
testID="addToDoItem"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With