Skip to content

fix: match Android Text in *ByRole queries when accessible is false - #1966

Merged
mdjastrzebski merged 3 commits into
callstack:mainfrom
Priyanshu0007:fix/android-text-by-role
Nov 30, 2026
Merged

mdjastrzebski merged 3 commits into
callstack:mainfrom
Priyanshu0007:fix/android-text-by-role

Conversation

@Priyanshu0007

Copy link
Copy Markdown
Contributor

Summary

Fixes #1963.

On Android, React Native's Text passes accessible={false} to its host when it has no onPress or onLongPress (Text.js). On iOS it passes true. isAccessibilityElement returned an explicit accessible prop as is, and *ByRole checks it before anything else. So on Android, no Text without a press handler was found by its role: getByRole('header') missed every heading and getByRole('text') every text.

On Android, accessible maps to native focusable, not to whether TalkBack reads the element (RN docs). A non-focusable Text is still read. This PR makes isAccessibilityElement treat a host Text as an accessibility element on Android whatever its accessible prop is.

  • iOS is unchanged: accessible={false} still removes a Text from *ByRole, as it does for VoiceOver.
  • Hidden Text is still excluded on Android: importantForAccessibility="no-hide-descendants", display: 'none', aria-hidden and modal siblings go through isHiddenFromAccessibility as before.
  • At the host level, React Native's default 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.
  • The bug didn't show with React Native's Jest preset because its Text mock doesn't set accessible. It showed after jest.unmock('react-native/Libraries/Text/Text'), or under runners that render React Native's own Text.
  • TextInput and Switch also map accessible to focusable on Android. They are left out of this PR to keep it focused.

The *ByRole docs note now says that Android Text stays an accessibility element with accessible={false}. docs/ was regenerated.

Test plan

  • Reproduced the issue on main (564a842) with React Native 0.88.0-rc.1, the repo's version: a test that unmocks Text and runs queryByRole('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.
  • New tests, using jest.replaceProperty(Platform, 'OS', ...):
    • isAccessibilityElement: on Android, a host Text is an accessibility element with accessible undefined, true and false.
    • *ByRole: on Android, Text with accessible={false} is found by role, with and without name.
    • *ByRole: on Android, Text with importantForAccessibility="no-hide-descendants" is still not found.
    • *ByRole: on iOS, Text with accessible={false} is still not found.
  • The two Android tests fail without the fix in src/helpers/accessibility.ts and pass with it.
  • yarn validate passes: typecheck, 87 suites and 958 tests, lint, format.
  • Gap: the full suite runs on the preset's default iOS platform only. The end-to-end Android check used a temporary Jest config that is not part of this PR.

Priyanshu0007 and others added 3 commits November 21, 2026 13:33
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
@mdjastrzebski

Copy link
Copy Markdown
Member

After review, I've decided to merge this fix. Please note, that RNTL is not developed or tested to work correctly with presents other that official RN Jest Preset. Using alternatives like Jest Expo or Vitest Native may or may not work correctly

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.57%. Comparing base (564a842) to head (f80916b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1966   +/-   ##
=======================================
  Coverage   98.56%   98.57%           
=======================================
  Files          87       87           
  Lines        1748     1750    +2     
  Branches      480      481    +1     
=======================================
+ Hits         1723     1725    +2     
  Misses         24       24           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mdjastrzebski
mdjastrzebski merged commit 32b3d1e into callstack:main Nov 30, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

*ByRole finds no Text on Android: React Native's own Text passes accessible={false} there

2 participants