-
Notifications
You must be signed in to change notification settings - Fork 276
Description
Describe the issue
According to accessible prop documentation, setting it to true "groups its children into a single selectable component". Then there is following example:
<View accessible={true}>
<Text>text one</Text>
<Text>text two</Text>
</View>with following comment: "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."
I understand the above statement that there is no concept nested accessible elements. If you are able to "focus" on some element, then it is treated as a whole by accessibility APIs, you cannot "focus" on any of its descendants. In other words there "focusable" components form a linear structure (similar to tabIndex attribute on Web) and not a tree structure when you could nest "focusable" element inside other "focusable" element.
We should consider including that behaviour in *ByRole queries, and how does it affect other A11y related functions like upcoming hidden query option #1064, isInaccessible function, etc.
Some examples:
getByRole('button', { hidden: false })should return only outerPressable, becausePressablerenders hostViewwithaccessible={true}by default. InnerPressableis not "focusable" because the outerPressableforms a single focusable unit for assitive technology.
<Pressable accessibilityRole="button" testID="outer">
<Pressable accessibilityRole="button" testID="inner">
<Text>Press me</Text>
</Pressable>
</Pressable>getByRole('button', { hidden: false })should return only innerPressable, because overridingaccessibleprop of outer pressable excludes it from reaching by assistive technology:
<Pressable accessibilityRole="button" testID="outer" accessible={false}>
<Pressable accessibilityRole="button" testID="inner">
<Text>Press me</Text>
</Pressable>
</Pressable>In case of using hidden: true option, aka respectAccessibility: false, the above test cases would return both outer and inner Pressables.
Possible Implementations
We might modify isInaccessible helper that will form the basis of exclusion for hidden accessibility elements in #1064. That way descendants of element with accessible={true} could be marked as inaccessible, while the element itself will be accessible.
This behaviour is related to upcoming hidden option, with the default behaviour being initially hidden: true aka respectAccessibility: false, so that should not make a breaking change. In the longer term we plan change it to false, as in RTL/DTL and only then this would be a breaking change.
Related Issues
@AugustinLF @thymikee @pierrezimmermannbam @MattAgn I'd would like to gather your feedback on proposed change, whether you see any potential issues,