Skip to content

fix: The fields of code are not announced#85504

Open
truph01 wants to merge 11 commits intoExpensify:mainfrom
truph01:fix/84304
Open

fix: The fields of code are not announced#85504
truph01 wants to merge 11 commits intoExpensify:mainfrom
truph01:fix/84304

Conversation

@truph01
Copy link
Contributor

@truph01 truph01 commented Mar 17, 2026

Explanation of Change

The magic code input fields (used for OTP / verification codes) were not announced by screen readers when the user navigated between digit positions. This made the component inaccessible — screen reader users had no way to know which digit they were editing.
Changes:

  1. Added a live-region announcement — When the focused digit index changes (via arrow keys, typing, backspace, or tap), the component now announces "enter digit X of N" to the screen reader. This is handled per-platform:
    • Web: A hidden <Text> element with role="alert" and accessibilityLiveRegion="assertive" (maps to aria-live="assertive" in the DOM). A zero-width space toggle ensures re-announcement even when navigating back to the same digit.
    • Android: The same accessibilityLiveRegion="assertive" is natively supported by TalkBack.
    • iOS: AccessibilityInfo.announceForAccessibility() is called explicitly, since iOS has no live-region equivalent.
  2. Hid digit placeholder Views from the accessibility tree — Added accessibilityElementsHidden and importantForAccessibility="no-hide-descendants" to each digit cell so the screen reader doesn't navigate to them individually. The hidden TextInput remains the single focusable element, and the announcements provide the per-digit context.
  3. Added enterDigitLabel translation — Added the new accessibility string to all 10 language files (en, de, es, fr, it, ja, nl, pl, pt-BR, zh-hans).

Fixed Issues

$ #74882
PROPOSAL:

Tests

Prerequisites: The user is signed in

  1. Using Chrome + JAWS, open the URL – https://new.expensify.com/
  2. Navigate using the Tab key to the Account button and press Enter to activate it.
  3. Continue unit it goes to Step 2 of 3: Verify
  4. Navigate to focus on the code input, using arrow key to move between 6 fields.
  5. Verify: Each field is announced like "enter digit 1 of 6"
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: These must be filled out, or the issue title must include ""[No QA].""

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained ""why"" the code was doing something instead of only explaining ""what"" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named ""index.js"". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-03-17.at.11.55.02.mov

https://meet.google.com/kwt-sgnz-ycohttps://meet.google.com/kwt-sgnz-ycoasd

Android: mWeb Chrome
Screen.Recording.2026-03-17.at.12.17.48.mov
iOS: Native
Screen.Recording.2026-03-17.at.12.28.05.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-03-17.at.11.42.44.mov

@melvin-bot
Copy link

melvin-bot bot commented Mar 17, 2026

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@truph01
Copy link
Contributor Author

truph01 commented Mar 17, 2026

@MelvinBot Please review this PR

@MelvinBot
Copy link
Contributor

🤖 Code Review

Nice work adding screen reader announcements to MagicCodeInput! The overall approach is solid — hiding digit cells from the accessibility tree and using a hidden live-region <Text> for announcements. A few items to address:


1. (High) Reuse the existing useAccessibilityAnnouncement hook

The codebase already has a platform-specific useAccessibilityAnnouncement hook (src/hooks/useAccessibilityAnnouncement/) used by FormHelpMessage.tsx. The PR reinvents the iOS and Android announcement logic inline. Consider extending or reusing that hook instead of duplicating platform-specific behavior.

2. (Medium) Missing iOS accessibility tree sync delay

The existing useAccessibilityAnnouncement/index.ios.ts wraps AccessibilityInfo.announceForAccessibility() in a 100ms setTimeout because:

On iOS real devices, a brief delay helps the accessibility tree sync before announcing.

The PR calls it directly without a delay (line 228-229):

if (Platform.OS === 'ios') {
    AccessibilityInfo.announceForAccessibility(message);
}

This may cause VoiceOver on real iOS devices to swallow announcements during rapid focus changes. Add the delay or reuse the existing hook.

3. (Medium) useState placement

The announcement state (line 216) is declared far from the other useState calls (lines 169-172), separated by multiple useEffect hooks and callbacks. This breaks the component's convention. Please move it up to group with the other state declarations.

4. (Low) Redundant accessibility props on inner cursor View

The cursor container View (line 553-558) already had accessibilityElementsHidden, importantForAccessibility="no-hide-descendants", and accessible={false}. The added aria-hidden is redundant since the parent View now also has the first two props, hiding the entire subtree. Not a blocker, but could be cleaned up.


What looks good

  • The zero-width space toggle for web re-announcements is a well-known aria-live pattern — correctly implemented
  • useEffect dependencies are complete (focusedIndex, maxLength, translate)
  • CONST.ROLE.ALERT and styles.hiddenElementOutsideOfWindow both exist and are used correctly
  • accessibilityElementsHidden + importantForAccessibility="no-hide-descendants" is the correct cross-platform pattern (iOS VoiceOver + Android TalkBack)
  • Translations added to all 10 language files under common.enterDigitLabel
  • Performance impact is negligible (one extra re-render per user-driven focus change)

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/MagicCodeInput.tsx 56.45% <100.00%> (+1.86%) ⬆️
... and 27 files with indirect coverage changes

@github-actions
Copy link
Contributor

🚧 @amyevans has triggered a test Expensify/App build. You can view the workflow run here.

@truph01 truph01 marked this pull request as ready for review March 17, 2026 18:01
@truph01 truph01 requested review from a team as code owners March 17, 2026 18:01
@melvin-bot melvin-bot bot requested review from aimane-chnaif and joekaufmanexpensify and removed request for a team March 17, 2026 18:01
@melvin-bot
Copy link

melvin-bot bot commented Mar 17, 2026

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team March 17, 2026 18:01
editIndex.current = index;
};

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-6 (docs)

The announcement value is purely derived from focusedIndex, maxLength, and translate -- it can be computed directly in the component body instead of using a useEffect + useState pair. The current approach introduces an unnecessary extra render cycle: first focusedIndex changes and the component renders with the stale announcement, then the effect fires, calls setAnnouncement, and triggers a second render with the correct value.

Replace the useState + useEffect with a derived value:

// Remove: const [announcement, setAnnouncement] = useState('');
// Remove: the useEffect that sets announcement

// Add: derive directly in the component body
const announcement = focusedIndex === undefined ? '' : translate('common.enterDigitLabel', {digitIndex: focusedIndex + 1, totalDigits: maxLength});

Both consumers (useAccessibilityAnnouncement and the hidden <Text> live region) will work identically with the derived value, since they only read the string.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

accessibilityLiveRegion="assertive"
>
{announcement}
</Text>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it work without this hidden Text?
useAccessibilityAnnouncement is now supporting web thanks to #85166

@MelvinBot
Copy link
Contributor

🤖 Code Review (Updated)

Good improvement — the updated PR now uses the existing useAccessibilityAnnouncement hook and groups state properly. Most of the earlier feedback has been addressed. A few remaining items:


1. (Medium) Potential double-announcement on native platforms

The PR announces on native via two mechanisms simultaneously:

  • useAccessibilityAnnouncement(announcement, ..., {shouldAnnounceOnNative: true}) → calls AccessibilityInfo.announceForAccessibility() on iOS/Android
  • The hidden <Text role="alert" accessibilityLiveRegion="assertive"> → also triggers TalkBack/VoiceOver

FormHelpMessage avoids this by conditionally rendering the hidden <Text> only on web (gated by shouldUseSeparateWebLiveAnnouncement which checks isWeb). The web hook is a complete no-op, so the hidden <Text> is essential for web — but on native it may cause duplicate announcements.

Suggestion: Either:

  • Gate the hidden <Text> to web-only (matching FormHelpMessage's pattern), OR
  • Remove {shouldAnnounceOnNative: true} and let the hidden <Text> handle announcements on all platforms

2. (Low) Redundant aria-hidden on cursor View

The aria-hidden added to the inner cursor View (line ~550) is redundant since the parent digit cell View already has accessibilityElementsHidden and importantForAccessibility="no-hide-descendants", which hides the entire subtree. Not a blocker, but could be cleaned up.


What looks good

  • Hook usage is correctuseAccessibilityAnnouncement(announcement, announcement.length > 0, {shouldAnnounceOnNative: true}) properly enables Android announcements via the shouldAnnounceOnNative flag
  • Blur/refocus cycle works correctly — when focusedIndex goes to undefined, the hook resets its previousAnnouncedMessageRef, so re-focusing the same digit correctly re-announces
  • State placementannouncement state is now grouped with other useState declarations
  • Dependencies are complete[focusedIndex, maxLength, translate] covers all values in the effect
  • Hidden <Text> pattern matches the established FormHelpMessage approach
  • Translations properly added to all 10 language files
  • All CI checks pass (the only failure is PR Reviewer Checklist / checklist, which is expected)

Copy link
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No product review needed

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b447c35f4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@rushatgabhane
Copy link
Member

@truph01 gentle bump

@aimane-chnaif
Copy link
Contributor

aimane-chnaif commented Mar 19, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari web

@MelvinBot
Copy link
Contributor

🤖 Code Review (Updated — v3)

The reworked PR is a clear improvement: using the existing useAccessibilityAnnouncement hook, deriving the announcement directly from focusedIndex (no useState), and removing the inline hidden <Text>. All checks pass except the PR Author Checklist. One issue remains:


(High) role="alert" + aria-live="polite" conflict on web

In src/hooks/useAccessibilityAnnouncement/index.ts:64-69:

const node = document.createElement('div');
node.setAttribute('role', 'alert');
if (shouldAnnouncePolite) {
    node.setAttribute('aria-live', 'polite');
}

Per WAI-ARIA, role="alert" has an implicit aria-live="assertive". Setting aria-live="polite" on the same element creates contradictory semantics — screen reader behavior is undefined (some honor the explicit attribute, others defer to the role's implicit mapping).

Compounding this, the parent wrapper (line 33) also has aria-live="assertive":

wrapper.setAttribute('aria-live', 'assertive');

So even if the inner node resolved to polite, the parent's assertive region would likely cause assertive announcement anyway.

Suggested fix: When shouldAnnouncePolite is true:

  • Use role="status" instead of role="alert" (implicit aria-live="polite")
  • Or omit the role entirely and just set aria-live="polite" + aria-atomic="true"
  • Consider whether the parent wrapper's aria-live="assertive" should also be made conditional

What looks good

  • Hook reuse — Uses the existing useAccessibilityAnnouncement hook instead of reinventing platform logic inline
  • State derivationannouncement is derived directly from focusedIndex (no useState), addressing the PERF-6 flag
  • No hidden Text in JSX — The previous <Text role="alert" accessibilityLiveRegion="assertive"> was removed, eliminating the Android double-announcement risk
  • Type safety — Passing undefined when focusedIndex is undefined is valid (ReactNode includes undefined), and the hook early-returns via the !shouldAnnounceMessage check
  • Digit cell hidingaccessibilityElementsHidden + importantForAccessibility="no-hide-descendants" correctly hides visual cells from screen readers
  • Translations — All 10 language files have enterDigitLabel
  • All CI checks passing (ESLint, typecheck, tests, perf-tests, etc.)

Minor note

shouldAnnouncePolite is silently ignored on iOS and Android (the native AccessibilityInfo.announceForAccessibility() API doesn't support a polite/assertive distinction). This is a platform limitation, not a bug, but a JSDoc comment on the type noting it's web-only would prevent future confusion.

@aimane-chnaif
Copy link
Contributor

(High) role="alert" + aria-live="polite" conflict on web

@truph01 what do you think of this concern?

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cdb1050de

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +519 to +520
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the entered code value accessible to screen readers

Hiding every digit cell here removes the only accessible copy of the code. The backing TextInput still uses value={input}, and setInputAndIndex() clears that state whenever the cursor moves, so after this change a screen reader can only hear the generic input label plus the new position alert. In OTP/PIN flows, users revisiting a slot can no longer tell whether it already contains a digit or what they are correcting.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Do you have any suggestions on this?

Should we update the announcement parameter passed in useAccessibilityAnnouncement so that it also reflects the current digit?

@aimane-chnaif
Copy link
Contributor

Please address AI reviews. Otherwise looks good

@MelvinBot
Copy link
Contributor

Yes — you can replace the entire inline platform logic with useAccessibilityAnnouncement. Here's what the refactored version would look like:

const announcement = focusedIndex !== undefined
    ? translate('common.enterDigitLabel', {digitIndex: focusedIndex + 1, totalDigits: maxLength})
    : '';

useAccessibilityAnnouncement(announcement, focusedIndex !== undefined, {
    shouldAnnounceOnNative: true,
    shouldAnnounceOnWeb: true,
});

This replaces the useState + useEffect + Platform.OS branching entirely. Here's why it works on all platforms:

Platform How the hook handles it
iOS index.ios.ts — calls AccessibilityInfo.announceForAccessibility() with a 100ms delay for accessibility tree sync. Deduplicates by message content, so changing from "digit 1" to "digit 2" triggers a new announcement.
Android index.native.ts — calls AccessibilityInfo.announceForAccessibility() immediately when shouldAnnounceOnNative is true. Same message-based dedup.
Web index.ts — injects a hidden <div aria-live="assertive"> into the DOM and appends a <div role="alert"> with the message after a 300ms delay. When the message changes, the effect's cleanup resets prevShouldAnnounceRef, so the new message gets announced.

Since the hook manages its own hidden DOM element on web, you can also remove the <Text role="alert" accessibilityLiveRegion="assertive"> element from the component's JSX — the hook handles that internally.

The AccessibilityInfo and Platform imports can also be removed since the hook abstracts those away.

What stays the same: The accessibilityElementsHidden + importantForAccessibility="no-hide-descendants" props on the digit cell <View> elements are still needed — those hide the visual cells from the screen reader tree, which is separate from the announcement mechanism.

@truph01
Copy link
Contributor Author

truph01 commented Mar 19, 2026

(High) role="alert" + aria-live="polite" conflict on web
@truph01 what do you think of this concern?

I removed aria-live="polite" logic totally.

@aimane-chnaif
Copy link
Contributor

(High) role="alert" + aria-live="polite" conflict on web
@truph01 what do you think of this concern?

I removed aria-live="polite" logic totally.

What was that fix for?

@truph01
Copy link
Contributor Author

truph01 commented Mar 19, 2026

What was that fix for?

@aimane-chnaif Previously, I added aria-live="polite" to ensure the announcement wouldn’t interrupt other screen reader output. However, I now think it’s redundant, so I’ve reverted that change.

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull main again once lint error is fixed

@melvin-bot
Copy link

melvin-bot bot commented Mar 19, 2026

We did not find an internal engineer to review this PR, trying to assign a random engineer to #74882 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@melvin-bot melvin-bot bot requested a review from aldo-expensify March 19, 2026 19:17
@aldo-expensify
Copy link
Contributor

Waiting for Eslint/Typescript errors to be fixed..

@aimane-chnaif
Copy link
Contributor

@truph01 pull main again. It's fixed now

@truph01
Copy link
Contributor Author

truph01 commented Mar 19, 2026

@aimane-chnaif @aldo-expensify All good now!

@truph01
Copy link
Contributor Author

truph01 commented Mar 23, 2026

I resolved conflicts

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.

6 participants