Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the accessibilityIdentifier on a React Native component?

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?

like image 222
bryanjclark Avatar asked Jan 10 '18 01:01

bryanjclark


People also ask

How do you set the accessibility focus in 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.

How do you check accessibility in react native?

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.

How do you use accessibility ID?

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”.

What is Accessibilitylabel?

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.


1 Answers

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"
/>
like image 93
Naishy Avatar answered Sep 25 '22 05:09

Naishy