Skip to content

[Due for payment 2026-10-27] [$175] Attachments - Chat scroll bar moves by arrow keys when PDF is opened #103576

Closed

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.6-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/77775812/folder/13176710/41236944/1840289884
Email or phone of affected tester (no customers): emady.11@gmail.com
Issue reported by: Applause Internal Team
Bug source: Regression TC Execution
Device used: windows 11 / Chrome
App Component: Chat Report View

Action Performed:

Precondition
Chat is present with attachments and PDF
Chat history should be available so the scroll bar appears

  1. Open staging.new.expensify
  2. Go to chat from precondition
  3. Open PDF file ( do not click on PDF after opening it )
  4. Press keyboard up and down arrows

Expected Result:

PDF should move Up and Down.

Actual Result:

Chat scroll bar is moving Up and Down.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7281581_1791492006221.Recording__1243.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7281581

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 9, 2026
  2. MelvinBot commented on Oct 9, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    When you open a chat attachment to view it, nothing inside the modal gets keyboard focus. That means the PDF's scroll container never receives the arrow keys.

    1. The modal's initialFocus returns false unless there is a Send button. The Send button only shows up in the add-attachment flow, so a viewed attachment has no initial focus target.
    2. When the focus trap activates, onActivate blurs the thumbnail you clicked. After that, document.activeElement is <body>.
    3. With <body> focused, Chrome sends ArrowUp/ArrowDown to the scroll container around the last-clicked node. That node is the PDF thumbnail in the chat list, which stays mounted behind the modal. So the chat list scrolls.
    4. react-fast-pdf gives the PDF list's outer div tabIndex=-1 so keyboard scrolling works, but it never focuses that div. The PDF only responds to arrow keys after you click inside it, which matches the "do not click on PDF" step.
    Code references

    What changes do you think we should make in order to solve the problem?

    In the web PDFView, focus the PDF's scroll container once it renders. Apply this only when the PDF is the active item in the attachment modal.

    • Add a ref to the outer View.
    • Add an effect gated on isUsedInAttachmentModal && !isUsedAsChatAttachment && isFocused !== false && !shouldUsePDFGestureZoom.
    • The list renders asynchronously after the PDF loads. Use a MutationObserver to wait for the [tabindex="-1"] scroll element inside the container.
    • When the element appears, call focus({preventScroll: true}) on it, unless focus is already inside the container. This keeps focus on the password form input for protected PDFs. Then disconnect the observer, and also disconnect it on cleanup.

    Because this focus happens after the trap's activation blur, the blur won't undo it. Off-screen carousel items are skipped because of the isFocused gate.

    What alternative solutions did you explore? (Optional)

    • Add an autoFocus prop or a listOuterRef prop to react-fast-pdf, then bump the version in App. This is cleaner, but it needs a library release.
    • Give the modal an initialFocus fallback, such as the carousel container. This stops the chat from scrolling but still won't scroll the PDF, because the focused element would sit above the scroller.
    Confidence and open questions
    • I traced the root cause through the code but haven't reproduced it in a browser.
    • The App checkout is shallow, so I couldn't confirm which change caused the regression. The issue reproduces in production, so it may have existed for a long time.
    • Image attachments probably let the chat scroll behind them too. It goes unnoticed because images don't scroll.

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/103576) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 9, 2026
  4. melvin-bot commented on Oct 9, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @nyomanjyotisa (External)

  5. changed the title [-]Attachments - Chat scroll bar moves by arrow keys when PDF is opened[/-] [+][$175] Attachments - Chat scroll bar moves by arrow keys when PDF is opened[/+] on Oct 9, 2026
  6. melvin-bot commented on Oct 9, 2026

    @melvin-bot
  7. yuvrajangadsingh commented on Oct 9, 2026

    @yuvrajangadsingh
    Contributor

    withdrawing this, it went up before the issue had the Help Wanted label. will come back if the label is added.

  8. camesenin commented on Oct 9, 2026

    @camesenin
  9. melvin-bot commented on Oct 9, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  10. krsnak commented on Oct 9, 2026

    @krsnak

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On Chrome, opening a PDF attachment and pressing Up/Down without clicking inside the PDF scrolls the chat behind the attachment viewer instead of the PDF.

    What is the root cause of that problem?

    The attachment modal does not transfer keyboard focus to the PDF's actual scrollable element. The modal focus trap clears the previous focus, while the PDFView wrapper is not the inner scroll container created by react-fast-pdf. Therefore the browser routes arrow-key scrolling to the background chat.

    What changes do you think we should make in order to solve the problem?

    In the web PDF attachment viewer, place focus on the PDF previewer's scroll element after it mounts, only when that PDF is the active attachment. Preserve focus if the user is interacting with a password prompt or another control, and restore normal focus behavior on close. Avoid a global arrow-key handler that could interfere with accessibility or other modals.

    I'll test Up/Down immediately after opening the PDF, after changing carousel items, with password-protected PDFs, and after closing the modal, including a regression check that the chat no longer scrolls behind it.

  11. taieddie commented on Oct 10, 2026

    @taieddie

    Contributor details
    Your Expensify account email: taieddie8@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01af851c9a7f771775

    Proposal (updated)

    Please re-state the problem that we are trying to solve in this issue.

    When opening a PDF attachment in the attachment modal on Web or Desktop, pressing the arrow keys (ArrowUp / ArrowDown) without clicking inside the preview first scrolls the background chat list instead of scrolling the PDF document.

    What is the root cause of that problem?

    A few factors come together to cause this:

    1. In src/pages/media/AttachmentModalScreen/AttachmentModalContainer/index.tsx, initialFocus evaluates to false when viewing existing attachments because contentProps.submitRef is only present during upload and confirmation flows.
    2. In src/components/FocusTrap/FocusTrapForModal/index.web.tsx, when the modal opens, blurActiveElement() blurs whatever was active, leaving document.activeElement on document.body.
    3. When document.body holds focus, browsers route ArrowUp and ArrowDown scrolling to the last active scrollable container in the document hierarchy. In our case, that is the chat's ReportActionsList sitting directly behind the modal overlay.
    4. Upstream react-fast-pdf (src/helpers.ts) already sets ref.tabIndex = -1 on the virtualized <List> outer container via outerRef={setListAttributes} to support programmatic focus without creating an unwanted sequential Tab stop. However, nothing in Expensify/App currently calls .focus() on that element when the attachment modal opens or when carousel slides transition.
    5. In src/components/PDFView/index.tsx, tabIndex={0} is assigned to an outer wrapper <View>, but that wrapper has overflow: hidden and is never focused anyway, causing keyboard arrow events to bypass the PDF preview completely until clicked.

    What changes do you think we should make in order to solve the problem?

    In src/components/PDFView/index.tsx:

    1. Remove tabIndex={0} from the outer <View> in renderPDFView(). Because that container has overflow: hidden, setting a tab index there is unnecessary and introduces a redundant tab stop.
    2. Attach a ref (containerRef = useRef<View>(null)) to that outer wrapper <View>.
    3. Add a useEffect hook to handle programmatic focusing whenever the PDF is active in the attachment modal (checking !shouldUsePDFGestureZoom && !!isUsedInAttachmentModal && !isUsedAsChatAttachment && isFocused !== false):
      • Target the scroller directly using .react-pdf__Document > [tabindex="-1"].
        This child selector is key: in react-fast-pdf, <List outerRef={setListAttributes}> renders as an immediate child of .react-pdf__Document once pages are ready. For password-protected PDFs, the password input wrapper inside BaseTextInput also happens to have tabIndex={-1}, but it sits outside .react-pdf__Document. Targeting .react-pdf__Document > [tabindex="-1"] ensures our observer will never accidentally match the password input wrapper or disconnect early before the user unlocks the document.
      • Use a MutationObserver on the container to observe when the PDF scroller mounts into the DOM. Once found, focus the scroller with scrollContainer.focus({preventScroll: true}) and disconnect the observer.
      • Respect active focus: do not steal focus if the user has already focused or clicked a modal header control (such as the Close or Download buttons).
      • Set role="region" and aria-label={fileName || translate('attachmentView.unknownFilename')} on the scroll container for accessibility.
    4. Clean up the observer when unmounting or switching slides.

    What alternative solutions did you explore? (Optional)

    1. Modifying upstream react-fast-pdf to auto-focus:
      Beyond requiring an upstream release and App dependency bump, the upstream library has no awareness of App carousel state (like isFocused). If upstream focused on mount, off-screen pre-rendered carousel slides would steal focus from the current slide.
    2. Capturing arrow keys globally in AttachmentModalContainer:
      Manually handling keydown and calling .scrollBy() reinvents native browser scrolling, loses smooth OS scroll acceleration, and risks conflicting with existing modal shortcuts.
    3. Using setTimeout or requestAnimationFrame:
      Timer-based approaches are prone to race conditions, particularly on slower devices or larger PDFs where PDF.js page rendering takes variable time. A MutationObserver reacts immediately once the DOM node is ready without arbitrary delays.

    Test Plan

    1. Open any chat report that has enough message history for the chat scrollbar to be visible.
    2. Click on a multi-page PDF attachment to open it in the attachment modal.
    3. Without clicking inside the PDF preview, press ArrowDown and ArrowUp on your keyboard:
      • Verify that the PDF document scrolls up and down smoothly.
      • Verify that the chat scrollbar in the background stays completely still.
    4. If there are multiple attachments in the report, switch between slides using the carousel arrows:
      • Navigate to a PDF attachment slide.
      • Without clicking inside the preview, press ArrowDown and ArrowUp to confirm the active PDF scrolls immediately.
    5. Open a password-protected PDF attachment:
      • Verify that the password input field receives focus cleanly and arrow keys do not interfere with typing.
      • Enter the password and unlock the document. Once the pages render, verify that arrow keys scroll the unlocked PDF.
    6. Verify on Mobile Web and Native platforms:
      • Verify pinch-to-zoom, gesture zoom, and touch scrolling remain smooth and unaffected.
    7. Close the modal:
      • Verify focus restores cleanly and normal chat navigation works as expected.
  12. 31 remaining items

  13. nyomanjyotisa commented on Oct 21, 2026

    @nyomanjyotisa
    Member

    Contributor+ Checklist:

    • [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to the comment on the PR: N/A — no offending PR identified.
      Link to the comment on the Issue: N/A.

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion: N/A — non-critical.

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal

    Retain these checks in the existing regression case linked in the issue.

    Precondition:

    • Desktop web; chat with scrollable history and a multi-page PDF.

    Test:

    1. Open the PDF without clicking inside it.
    2. Press Down, then Up.
    3. Verify the PDF scrolls and the background chat stays still.

    Do we agree 👍 or 👎

  14. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Oct 21, 2026
  15. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  16. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  17. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    @mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  18. mallenexpensify commented on Oct 30, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @nyomanjyotisa due $175 via NewDot

    Thx for the breakdown about the deploy blocker above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions