Repository navigation
fix: match Android Text in *ByRole queries when accessible is false - #1966
Open
Priyanshu0007 wants to merge 1 commit into
Open
Priyanshu0007 wants to merge 1 commit into
Priyanshu0007 wants to merge 1 commit into
Conversation
React Native's Text passes `accessible={false}` to its host on Android
when it has no press handler. On Android `accessible` maps to native
`focusable`, which does not stop TalkBack from reading the text, but
`isAccessibilityElement` returned the explicit prop, so `*ByRole` skipped
every such Text (e.g. `getByRole('header')`).
Treat host Text as an accessibility element on Android regardless of
`accessible`. iOS keeps honouring `accessible={false}`, and hidden Text
(`importantForAccessibility="no-hide-descendants"`, `display: none`, ...)
is still excluded.
Fixes callstack#1963
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1963.
On Android, React Native's
Textpassesaccessible={false}to its host when it has noonPressoronLongPress(Text.js). On iOS it passestrue.isAccessibilityElementreturned an explicitaccessibleprop as is, and*ByRolechecks it before anything else. So on Android, noTextwithout a press handler was found by its role:getByRole('header')missed every heading andgetByRole('text')every text.On Android,
accessiblemaps to nativefocusable, not to whether TalkBack reads the element (RN docs). A non-focusableTextis still read. This PR makesisAccessibilityElementtreat a hostTextas an accessibility element on Android whatever itsaccessibleprop is.accessible={false}still removes aTextfrom*ByRole, as it does for VoiceOver.Textis still excluded on Android:importantForAccessibility="no-hide-descendants",display: 'none',aria-hiddenand modal siblings go throughisHiddenFromAccessibilityas before.accessible={false}and one the user wrote can't be told apart. Natively they are the same (focusable=false), so both are handled the same way.Textmock doesn't setaccessible. It showed afterjest.unmock('react-native/Libraries/Text/Text'), or under runners that render React Native's ownText.TextInputandSwitchalso mapaccessibletofocusableon Android. They are left out of this PR to keep it focused.The
*ByRoledocs note now says that AndroidTextstays an accessibility element withaccessible={false}.docs/was regenerated.Test plan
main(564a842) with React Native 0.88.0-rc.1, the repo's version: a test that unmocksTextand runsqueryByRole('header', { name: 'Title' })passed under an iOS Jest config (accessible=true) and failed under an Android one (haste.defaultPlatform: 'android',accessible=false). With this change it passes on both.jest.replaceProperty(Platform, 'OS', ...):isAccessibilityElement: on Android, a hostTextis an accessibility element withaccessibleundefined,trueandfalse.*ByRole: on Android,Textwithaccessible={false}is found by role, with and withoutname.*ByRole: on Android,TextwithimportantForAccessibility="no-hide-descendants"is still not found.*ByRole: on iOS,Textwithaccessible={false}is still not found.src/helpers/accessibility.tsand pass with it.yarn validatepasses: typecheck, 87 suites and 958 tests, lint, format.