Repository navigation
Focus the PDF scroller in the attachment modal so arrow keys scroll the PDF - #103836
Conversation
…he PDF Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
The failing Analysis: Thread report drafts explicitly through the split-transaction update flow made Evidence:
Fix: Add |
|
🤖 Web test steps verification results: ❌ fail I couldn't run these steps on web, and I didn't see the fix fail. The web test tool can't upload a PDF to create the test chat, and it can't press the Up or Down arrow keys, which is what this fix is about. To verify this PR, test it by hand in Chrome.
|
| // The attachment modal has no initial focus target, so focus falls back to the body and arrow keys scroll the | ||
| // chat behind the modal. Focus the PDF scroller once it renders so arrow keys scroll the PDF instead. | ||
| useEffect(() => { | ||
| if (!isUsedInAttachmentModal || isUsedAsChatAttachment || isFocused === false || shouldUsePDFGestureZoom) { |
There was a problem hiding this comment.
@MelvinBot Normal PDFs, wrong-password retry and reopening passed locally. I think we should add regression tests for the new scroller-focus logic and observer cleanup.
Move the scroller focus logic into focusPDFScrollerWhenReady so it can be tested against a real DOM. Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
|
I added regression tests for the scroller-focus logic and the observer cleanup, and pushed them to this PR. All 7 new tests pass. To test against a real DOM, I moved the focus logic out of the
Checks
|
…entModal' into claude-focusPDFScrollerInAttachmentModal Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
|
Fixed the failing Typecheck now passes locally, and so does The remaining failures, |
Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
|
MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR. Next steps: A human should review the recent commits and resolve the conflicting CI errors manually. |
|
I fixed the failing After the push, |
|
@MelvinBot please replace the sections from Updated testing, checklist, and recordingsTests
Offline tests
QA StepsSame as Tests and Offline tests.
PR Author Checklist
Screenshots/VideosAndroid: NativeAndroid-pr103836-user.mp4Android: mWeb ChromeAndroid-mWeb-pr103836-user.mp4iOS: Nativeios-pr103836-user.mp4iOS: mWeb Safariios-mWeb-pr103836-user.mp4MacOS: Chrome / SafariChrome-pr103836-user.mp4 |
|
I replaced everything from All 7 unchecked items stay unchecked:
|
|
@MelvinBot please replace the sections from Updated testing, checklist, and recordingsTests
Offline tests
QA StepsSame as Tests and Offline tests.
PR Author Checklist
Screenshots/VideosAndroid: NativeAndroid-pr103836-user.mp4Android: mWeb ChromeAndroid-mWeb-pr103836-user.mp4iOS: Nativeios-pr103836-user.mp4iOS: mWeb Safariios-mWeb-pr103836-user.mp4MacOS: Chrome / SafariChrome-pr103836-user.mp4 |
|
I replaced everything from All 38 checklist items are now checked, including the 7 that were unchecked before. |
| const activeElement = document.activeElement; | ||
| const isFocusAvailable = !activeElement || activeElement === document.body || (container.contains(activeElement) && !scroller.contains(activeElement)); | ||
| if (isFocusAvailable) { | ||
| scroller.focus({preventScroll: true}); |
There was a problem hiding this comment.
@MelvinBot could we give the focused PDF scroller an accessible name? VoiceOver announces only “group”; using the filename worked locally, including after password unlock.
Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
|
I gave the focused PDF scroller an accessible name and pushed the change to this PR. It uses the file name and falls back to the same "unknown filename" text the PDF button uses.
The unit tests check the name in three cases: when the PDF loads, after password unlock, and when focus stays on the header. Lint, typecheck, spell check, the React Compiler check, and the 7 unit tests passed. I couldn't test with VoiceOver, so please confirm in Safari. |
|
@MelvinBot please mark this PR as ready for review. |
|
I marked this PR as ready for review. |
|
@nyomanjyotisa 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] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| return; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing |
There was a problem hiding this comment.
❌ CONSISTENCY-5 (docs)
This eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing has no accompanying justification comment, so a future maintainer can't tell why the rule is deliberately suppressed. Here the || is intentional because an empty-string fileName is falsy and should fall back to the default label, whereas ?? would keep the empty string.
Add a one-line justification above the disable, e.g.:
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
// `||` is intentional: an empty fileName should fall back to the default label, which `??` would not do
return focusPDFScrollerWhenReady(container, fileName || translate('attachmentView.unknownFilename'));Reviewed at: 30f5d61 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
I added the justification and pushed it to this PR. It's on the disable line itself, in index.tsx:235: -- Using || intentionally so an empty fileName falls back to the default label.
I didn't use the suggested layout. A comment between eslint-disable-next-line and the code moves the suppression onto the comment, so the || line would be flagged again. The inline -- form matches PressableWithDelayToggle.tsx and CopyTextToClipboard.tsx. Lint and the spell check pass.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid-pr103836-user.mp4Android: mWeb ChromeAndroid-mWeb-pr103836-user.mp4iOS: HybridAppios-pr103836-user.mp4iOS: mWeb Safariios-mWeb-pr103836-user.mp4MacOS: Chrome / SafariChrome-pr103836-user.mp4 |
|
@MelvinBot could you address the lint-suppression finding? |
Co-authored-by: Nyoman Jyotisa <nyomanjyotisa@users.noreply.github.com>
|
🚧 inimaga has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/inimaga in version: 9.5.14-0 🚀
|
|
No help site update needed. This is a bug fix that makes the arrow keys scroll an open PDF attachment, as users already expect, and no article on the help site describes how to scroll PDF attachments. |
|
Deploy Blocker #104390 was identified to be related to this PR. |
|
🚀 Deployed to production by https://github.com/grgia in version: 9.5.14-3 🚀
Bundle Size Analysis (Sentry): |
|
Follow-up #104390: Left/Right blurred the PDF even when the carousel could not move, stopping subsequent keyboard scrolling. Fixed in #104449 by blurring only when the attachment changes. @inimaga agreed with the assessment that this was not a production regression. |





Explanation of Change
When you open a chat attachment to view it, the attachment modal has no initial focus target. The focus trap also blurs the thumbnail you clicked, so focus falls back to
<body>. Chrome then sends ArrowUp/ArrowDown to the chat list behind the modal instead of the PDF.react-fast-pdfalready makes the PDF scroller (react-window's outer div) focusable withtabIndex=-1, but nothing focuses it. This PR updates the webPDFViewto focus that scroller once it renders, so arrow keys scroll the PDF right away.isUsedInAttachmentModal && !isUsedAsChatAttachment && isFocused !== false && !shouldUsePDFGestureZoom)..react-pdf__Document > [tabindex="-1"]. The password input wrapper also hastabIndex=-1, but it renders outside.react-pdf__Document, so it never matches.MutationObserverwatches the container until the scroller appears, then disconnects. It also disconnects on cleanup.<body>or elsewhere inside thePDFViewcontainer. It never takes focus from the modal header buttons.AI tests run by MelvinBot:
npm run lint -- src/components/PDFView/index.tsx(seatbelt) passednpm run react-compiler-compliance-check -- check src/components/PDFView/index.tsxpassednpm run spell-changedpassedtests/unit/NativePDFViewTest.tsxandtests/unit/IsAllowedPDFLinkTest.tspassed (46 tests)npm run typecheckfails only intests/actions/IOUTest/SplitTest.ts(reportDraftsmissing). That failure exists onmainand isn't related to this change.Fixed Issues
$ #103576
PROPOSAL: #103576 (comment)
Tests
Offline tests
QA Steps
Same as Tests and Offline tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android-pr103836-user.mp4
Android: mWeb Chrome
Android-mWeb-pr103836-user.mp4
iOS: Native
ios-pr103836-user.mp4
iOS: mWeb Safari
ios-mWeb-pr103836-user.mp4
MacOS: Chrome / Safari
Chrome-pr103836-user.mp4