Skip to content

fix(menu): trap screen readers and move focus on open/close - #5220

Open
zacyungblut wants to merge 1 commit into
callstack:mainfrom
zacyungblut:fix/menu-screen-reader-focus
Open

zacyungblut wants to merge 1 commit into
callstack:mainfrom
zacyungblut:fix/menu-screen-reader-focus

Conversation

@zacyungblut

Copy link
Copy Markdown

Summary

Fixes #5215.

When a Menu opens, TalkBack on Android keeps reading the page behind it: the menu renders through a plain <Portal>, so nothing hides the background from assistive technology, and the items only appear at the very end of the reading order. Focus also stays on the anchor, since focusFirstDOMNode only does anything on web.

Changes

  • Pass modal={visible} to the menu's Portal, the same mechanism Modal uses, so the page behind the open menu is hidden from screen readers and focus order on Android.
  • Replace the web-only focusFirstDOMNode with a cross-platform focusFirstNode: the web behavior is unchanged, and on native it calls AccessibilityInfo.setAccessibilityFocus on the menu when it opens and on the anchor when it closes, matching the focus handoff web already has.

Test plan

  • Existing Menu tests pass (no behavior changes on the paths they cover).
  • Code-level verified: findNodeHandle is guarded, the web branch is untouched, and the Portal modal prop mirrors Modal's own usage.
  • TalkBack/VoiceOver behavior should be confirmed on a device - I don't have one in this environment. Happy to adjust if the focus landing spot should be the first Menu.Item rather than the menu container.

@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.
  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

This branch has not been deployed

No deployments
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.

Menu: opening a Menu with a screen reader leaves focus on the anchor, and the items come last in the reading order

1 participant