-
Notifications
You must be signed in to change notification settings - Fork 272
Effect of accessible
prop on *ByRole
+ hidden
, inInaccessible
, etc
#1163
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
Comments
If I understand correctly, if this gets implemented with <Pressable>
<Text>Press me</Text>
</Pressable> This wouldn't work anymore since the Text element is inaccessible fireEvent.press(screen.getByText('Press me') This means that we would systematically have to use byRole queries for pressing buttons by text (which if I'm correct requires to add the accessibilityRole prop for now). Even though it probably is a better way to do it and it seems interesting to enforce it, this would be a major breaking change and could be quite hard to fix on large codebases. However What I'm more concerned about is that the behavior of queries becomes more and more complicated and unnatural to users, especially the ones that are not very familiar with how accessibility works. So while I think this goes in the right direction, this would need to be really well documented before being adopted. There should be a way to make this work, for instance with very good error messages and really good documentation but in any case making users understand what's going on should be an important focus for this feature imo |
I agree with @pierrezimmermannbam. I do think that the example provided should be valid, regardless of the options provided by the developer: const {getByText} = render(
<Pressable>
<Text>Press me</Text>
</Pressable>
)
// this should work, regardless of `hidden/respectAccessibility` value.
screen.getByText('Press me') We might need more granularity when it comes to detecting And we do want to raise an error for this case (because it is likely inaccessible), I don't think it should be done as part of any query, but a render check, akin to what we have for |
I also agree with @pierrezimmermannbam and @AugustinLF, it would be a major change for most projects and also not very natural at first. I feel like pressing buttons is one of the most common actions we do in tests. However if we were to add render(
<Pressable>
<Text>Press me</Text>
</Pressable>
)
pressButtonByText("Press me") |
Thanks for feedback. I share your concerns about affecting other queries, existing user tests, etc. accessible prop effect on screen reader
Based on these observations I think we should allow for searching inside elements with
DTL hidden option I think that in our case we would want to see Potential usage for accessible prop If we went that way, then nested |
Thank you all for discussion. Closing in favour of #1180 with more clear scope. |
Describe the issue
According to
accessible
prop documentation, setting it totrue
"groups its children into a single selectable component". Then there is following example: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 upcominghidden
query option #1064,isInaccessible
function, etc.Some examples:
getByRole('button', { hidden: false })
should return only outerPressable
, becausePressable
renders hostView
withaccessible={true}
by default. InnerPressable
is not "focusable" because the outerPressable
forms a single focusable unit for assitive technology.getByRole('button', { hidden: false })
should return only innerPressable
, because overridingaccessible
prop of outer pressable excludes it from reaching by assistive technology:In case of using
hidden: true
option, akarespectAccessibility: false
, the above test cases would return both outer and innerPressable
s.Possible Implementations
We might modify
isInaccessible
helper that will form the basis of exclusion forhidden
accessibility elements in #1064. That way descendants of element withaccessible={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 initiallyhidden: true
akarespectAccessibility: false
, so that should not make a breaking change. In the longer term we plan change it tofalse
, as in RTL/DTL and only then this would be a breaking change.Related Issues
#1161
#1064
#1128
@AugustinLF @thymikee @pierrezimmermannbam @MattAgn I'd would like to gather your feedback on proposed change, whether you see any potential issues,
The text was updated successfully, but these errors were encountered: