-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent duplicate accessibilityLabel on parent views #31924
Prevent duplicate accessibilityLabel on parent views #31924
Conversation
Base commit: cbec66e |
Base commit: cbec66e |
@@ -641,8 +641,14 @@ - (NSObject *)accessibilityElement | |||
|
|||
static NSString *RCTRecursiveAccessibilityLabel(UIView *view) | |||
{ | |||
NSMutableString *result = [NSMutableString stringWithString:@""]; | |||
NSMutableString *result = [NSMutableString string]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
At first glance, this looks fine to me. I would recommend getting out a physical device, turning on the screen reader, and testing the behavior before and after this change. (The screen reader doesn't work in the iOS simulator.) I think this PR is going to behave better than mine in that regard, but I don't know this stuff well enough to say for sure. In my case, the concerns were mainly performance related, and we mitigated it by special-casing React Native apps and bypassing RCTRecursiveAccessibilityLabel entirely. (I just now closed my PR.) (Also, FWIW, #31222 is kind of orthogonal to this, as it only improves performance without changing behavior.) |
Hi! Could you create a test in AccessibilityExample.js or AccessibilityIOSExample.js for this? |
@p-sun is my test adequate? |
Hi @p-sun is there anything I can do to help move this forward? |
I will take a look at this within the next three days. Thanks for waiting! |
Hi @p-sun will you have a chance to review this? |
Is there any chance this has been reviewed? |
Hi @p-sun will this get a review or should I close it? |
Summary
In testing React Native apps using Appium, the
accessibilityLabel
is an important prop which provides an additional means to lookup elements in addition to thetestID
. More importantly, theaccessibilityLabel
provides detail to screen readers and other accessibility helpers. React Native on iOS has custom logic (compared to Android), whereby it concatenates the accessibility labels of children. This is useful in a case such as this:The above creates the following accessibility view:
and when viewed in Appium Studio
However, if the above is in one or more views, such as:
You can get the following from XCUITest and Appium:
This happens because the parent Views are using
RCTRecursiveAccessibilityLabel()
to populate the label from the child Touchable. This doesn't make sense semantically because the TouchableHighlight is an accessible element. It benefits from the concatenation to create its label from the two Text elements, but the container views are not part of that label. They should not include it.This PR should fix #21830, and it represents a possibly lower impact alternative to #24113, #24118, #29801, and #31222. It's not clear what functionality is relying on the string concatenation as it is currently implemented.
Changelog
Change the recursion algorithm to include labels from accessible elements only if they are not other types of
RCTView
instances. For example,RCTTextView
should be included. This helps to minimize the impact of this change on other developers of custom views.[iOS] [Changed] - When iterating over subviews, ignore subviews that are accessible elements (e.g. Touchable).
Test Plan
Verified that accessibility labels on
<Touchable>
elements maintain existing behavior with nested Text elements.Verified that accessibility labels on non-accessible views do not include all child labels.
I added an example to
AccessibilityIOSExample.js
which can be used with VoiceOver to see the new behavior. In the example, text nested inside accessible subviews is not part of the spoken label.