react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Provide query option to respect accessibility

Open mdjastrzebski opened this issue 3 years ago • 6 comments

Describe the Feature

This issue is based on #787 PR. That PR is stale but idea seems worth pursuing.

Currently all queries ignored accessibility ignored the fact that certain element, e.g. screen or modal is present in component tree but not really visible to the user.

This problem largely does not exist in web React world as previous screens are removed from component tree, except modals, but it is relevant in React Native world. We even suggest some work arounds for it with within function.

Possible Implementations

  • Add additional respectAccessibility query options for all queries. This query options would be common to all query verbs (getBy, etc) and predicates (byText, etc).
  • By default it should be disabled to preserve API stability
  • If set explicitly to true it would ignore elements that are not accessible, by analysing e.g. accessibilityElementsHidden, importantForAccessibility, accessibilityViewIsModal, style={{ display: 'none' }}, etc
  • Consider switching this option to true by default by introducing a breaking change in next major release, as having it on by default is probably what users would expect.
  • We could salvage some a11y predicate code and possibly all tests from #787

Related Issues

  • #787 for initial idea

mdjastrzebski avatar May 04 '22 10:05 mdjastrzebski

@thymikee @AugustinLF any thoughts on the above?

mdjastrzebski avatar May 04 '22 10:05 mdjastrzebski

I'm in favor. However, I'd see this as a temporary solution until we're sure about the way it works is in a perfect sync with how react-native treats those accessibility traits. We should make it explicit from the beginning when documenting the feature.

thymikee avatar May 04 '22 11:05 thymikee

As in all other cases like queries we are doing our best but only imperfectly simulate RN runtime environment.

RTL for web can rely on JS DOM to have a very real-like environment so it has a much simpler work in that regard.

mdjastrzebski avatar May 04 '22 12:05 mdjastrzebski

The path you outline sounds worth pursuing IMO.

AugustinLF avatar Jun 07 '22 11:06 AugustinLF

I would also love to have that feature! @mdjastrzebski Can I help finishing the implementation?

MattAgn avatar Jul 27 '22 10:07 MattAgn

@MattAgn please do! 💯 This would be a very useful feature to have in RNTL!

mdjastrzebski avatar Aug 01 '22 21:08 mdjastrzebski