Skip to content

fix(ui): close open dropdown menu when a file drag enters the window - #13541

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/sidebar-menu-blocks-file-drop
Sep 27, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/sidebar-menu-blocks-file-drop

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Dropping a file onto the chat composer attaches it even when a sidebar menu is open.

Open a sidebar "..." menu (folder, session row, "New chat", filter/sort) or right-click a session row, then drag a file from the OS onto the chat composer. The drop overlay never appears and the file is not attached. Dropping works again only after the menu is closed by hand.

Why it matters

The sidebar is where a user browses while deciding which chat gets the file. Any open menu there silently swallows the drop, with no feedback, so it reads as "drag and drop is broken".

Not a goal

  • Wrapping Popover / Select roots: the four remaining modal sites render inside modal Dialogs that already cover the composer, so closing them would not make a drop reachable; a different fix if ever wanted.
  • Making the menus non-modal (modal={false}): that would let an outside click both close a menu and activate the sidebar row under it.
  • Changing drop-zone behaviour, accepted file types or attachment handling in ChatInput / ChatDropOverlay.

What changed (motivation → approach → change)

Punch line An open menu now closes the moment a file drag from outside the page enters the window, so the composer's drop zone gets the drop.
Rule website/src/hooks/useCloseOnFileDrag.ts: while a modal menu is open, a window dragenter carrying files calls the menu's close path.
Where website/src/components/ui/dropdown-menu.tsx and website/src/components/ui/context-menu.tsx: DropdownMenu and ContextMenu wrap the Radix Root instead of re-exporting it and apply the rule.
Detector website/src/lib/fileDrag.ts: carriesFiles(dataTransfer), moved out of ChatDropOverlay.tsx so the menu and the drop zone agree on what a file drag is.

Symptom: every <DropdownMenu> and <ContextMenu> in the dashboard is a modal Radix menu. While open, Radix sets pointer-events: none on document.body. HTML5 drag events honour that property, so nothing under the menu, the composer's drop zone (useChatFileDrop) included, receives dragover or drop.

Root cause: the menu never dismisses during the drag. Radix closes on an outside pointerdown, and a native file drag produces none. The drag is lost for as long as the menu stays open.

Change: the dragenter still reaches window (it fires on <html>, which body's pointer-events cannot hide; Radix's own click-outside dismissal relies on the same fact, since its pointerdown listener sits on the document). The hook listens there while a modal menu is open and, when the drag carries files, closes the menu through the same onOpenChange(false) path a click-outside uses. DropdownMenu keeps its controlled (open) and uncontrolled (defaultOpen) forms; ContextMenu opens only by right-click, so its wrapper owns the state and its prop type omits open. In-page drags (session rows, folder moves) are ignored; modal={false} menus never block the drop zone and are left alone. The drop zone then picks up the next dragover. This fixes all 53 <DropdownMenu> uses and the sidebar row <ContextMenu> at once; switching the sidebar menus to modal={false} was rejected because a non-modal menu lets an outside click both dismiss the menu and activate the row beneath it.

ChatDropOverlay.tsx only swaps its private carriesFiles for the shared import.

Backwards compatibility

Compatible: DropdownMenu accepts the same props as Radix Root and forwards them; ContextMenu drops open, which no caller passes (a future one gets a type error, not a silent ignore); the only new behavior is an extra close trigger while a modal menu is open.

Tests

website/src/test/DropdownMenu.fileDragClose.test.tsx (7 tests):

  • an uncontrolled defaultOpen menu unmounts its content and calls onOpenChange(false) on a window dragenter carrying Files;
  • a controlled open menu does the same through its onOpenChange;
  • in-page drags (text/plain, application/x-kiro-session) leave the menu open;
  • a modal={false} menu is left open;
  • after the menu closes by Escape, a later file drag calls nothing (listener removed);
  • a right-click ContextMenu closes on a file drag and reports onOpenChange(false), and ignores an in-page drag.

The three dismissal tests fail on origin/main (content stays mounted, onOpenChange never called) and pass with this change. Existing ChatDropOverlay.test.tsx and menuContentOverflow.test.tsx unchanged and green.

Manual verification

Real Chromium against a harness gateway (spawn_feature_gateway(fixture="minimal")) serving this head's built dist. The drag is produced with CDP Input.dispatchDragEvent, which goes through the renderer's real hit-testing, so body pointer-events: none under the open menu is exercised the way an OS drag exercises it (a synthetic DragEvent would bypass it). Script: evidence.mjs in the media ref linked below.

step this head (57eef3998) main (a992d5cd, same script)
sidebar "More options" menu open body pointer-events: none body pointer-events: none
dragEnter carrying a file at the window edge menu unmounted, body pointer-events: auto menu still mounted, body still none
dragOver the composer drop overlay mounted no overlay
drop hello.txt chip in the composer nothing attached

Screenshots / video

This head, during the drag and after the drop:

Drop overlay over the composer while the menu that was open has closed

hello.txt attached in the composer after the drop

Main (control, same script): menu stays open, nothing attaches

Main: cursor over the composer, no drop overlay, menu still open

Main: composer empty after the drop

Full captures and the result.json for both runs: refs/media/pr-13541 @ f156d01b.

Related Issues

Fixes #13540

Pattern harvest

Rule candidate: review-prompt
Pattern: a modal Radix layer (menu, popover) is re-exported bare; any new one must go through a wrapper that applies useCloseOnFileDrag, or a native file drag is swallowed while it is open.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Intent: A file dragged in from the OS while any dashboard dropdown menu is open must reach the chat composer drop zone; the open menu closes when the drag enters the window.
Not a goal: Changing menu modality (click-outside, scroll lock, focus behaviour) for any menu; Radix ContextMenu (no controlled open, different mechanism); drops onto surfaces other than the existing chat drop zones.

@Pearcekieser
Pearcekieser requested review from a team and cixuuz September 24, 2026 21:32
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of 69a4ed08850a582d1ae8f3ce7cb14e6f2c38ff31 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Verify with one real OS drag that the menu vanishing mid-drag reads as normal dismissal, not a glitch — stills cannot show it.

[UX-REVIEWED] 69a4ed0

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 69a4ed08850a582d1ae8f3ce7cb14e6f2c38ff31 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 69a4ed0

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 69a4ed08850a582d1ae8f3ce7cb14e6f2c38ff31 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the pending Frontend Lint & Type Check lane goes green: the ContextMenu wrapper depends on Radix Root accepting a controlled open prop.

[DESIGN-REVIEWED] 69a4ed0

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 69a4ed08850a582d1ae8f3ce7cb14e6f2c38ff31 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Confirm no out-of-tree edition passes a controlled open to ContextMenu — the wrapper now type-rejects it; all 4 in-repo consumers are safe (grepped <ContextMenu\b).

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX — a file dropped on the chat composer attaches even while a sidebar menu is open (issue #13540; three added tests fail on base).

  1. An open sidebar "..." dropdown menu closes the moment an OS file drag enters the window — justified
  2. An open right-click session-row context menu closes the same way — justified
  3. ContextMenu no longer accepts a controlled open prop; a future caller gets a type error — justified
  4. The "is this a file drag" check moved to shared lib/fileDrag.ts, now tolerating a missing dataTransfer — justified
  5. New hook useCloseOnFileDrag applied by both menu wrappers (2 counted consumers) — justified

[FIRST-PRINCIPLES-REVIEWED] 69a4ed0

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed 69a4ed08850a582d1ae8f3ce7cb14e6f2c38ff31 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 69a4ed0

@Pearcekieser
Pearcekieser force-pushed the fix/sidebar-menu-blocks-file-drop branch from a288c50 to 7203a7a Compare September 24, 2026 22:34
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

mechanism: shared hook useCloseOnFileDrag applied to both DropdownMenu and ContextMenu roots

  • ContextMenu on sidebar rows has the same defect — fixed in 7203a7a

Legitimate: Radix ContextMenu Root is modal by default and sets body pointer-events none the same way.
Radix 2.3.1 ContextMenu Root accepts a controlled open, so the same close path works; context-menu.tsx now wraps Root and applies the rule.
Test added: right-click menu closes on a file dragenter and reports onOpenChange(false); fails on base.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Browser premise verified only by reading Radix source — rebutted

The premise (events still reach the document while body is pointer-events:none) is the one Radix's own modal dismissal already depends on: DismissableLayer sets body.style.pointerEvents = "none" (react-dismissable-layer dist/index.mjs:113) and listens for the outside pointerdown on ownerDocument (index.mjs:293). Click-outside dismissal of every modal menu in the app works today only because a pointer event over the hidden body still hit-tests to <html> and reaches the document.
Drag events use the same hit-testing as pointer events, so dragenter reaches window under the same condition. This is CSS hit-testing behaviour, not a Radix implementation detail.
A native OS file drag cannot be produced by Playwright or a synthetic event, so no CI or harness evidence is possible; the branch is not deployed anywhere a human can drag onto. The author will confirm on the live dashboard after merge and reopen #13540 if the menu does not close.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Extract the effect as a shared hook — fixed in 7203a7a

website/src/hooks/useCloseOnFileDrag.ts holds the effect; dropdown-menu.tsx and context-menu.tsx both call it. close is read through a ref so an inline onOpenChange does not re-arm the listener per render.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • ContextMenu still raw Radix Root, same body pointer-events block — fixed in 7203a7a

context-menu.tsx now wraps ContextMenuPrimitive.Root with the same controlled/uncontrolled bridge as DropdownMenu and applies useCloseOnFileDrag; verified against the four production call sites (FileExplorerPage, BottomTerminalPanel, FilePathMenu, ChatSidebar), all uncontrolled.
Regression test: right-click menu closes on a window dragenter carrying Files; fails on base.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/sidebar-menu-blocks-file-drop branch from 7203a7a to 57eef39 Compare September 24, 2026 23:55
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: ContextMenu wrapper owns its open state; prop type omits open

  • Controlled open branch on ContextMenu has zero consumers — fixed in 57eef39

Branch deleted. The wrapper now holds the only open state and its prop type is Omit<RootProps, 'open'>, so a future controlled caller gets a type error instead of a silently ignored prop.
Radix's controlled-open support is confirmed for the record: @radix-ui/react-context-menu@2.3.1 ContextMenuProps declares open?: boolean (dist/index.d.mts:10) and Root wires it through useControllableState (dist/index.mjs:32); that is what lets the wrapper close the menu at all.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Does Radix ContextMenu Root accept controlled open? — rebutted with the installed type

@radix-ui/react-context-menu@2.3.1 ContextMenuProps is {children?, open?: boolean, onOpenChange?, dir?, modal?} (dist/index.d.mts:8-14); Root passes open: openProp into useControllableState (dist/index.mjs:19,32). close() therefore reaches Radix, not just the wrapper's mirror.
The ContextMenu dismissal tests in DropdownMenu.fileDragClose.test.tsx exercise exactly that path against the installed package and pass; Frontend Lint & Type Check passed on this head.
The unused controlled-open branch that prompted the doubt is removed in 57eef39 (see the first-principles disposition).

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • useState(false) ignores a supported defaultOpen prop — rebutted

Radix ContextMenu.Root has no defaultOpen: ContextMenuProps is {children?, open?, onOpenChange?, dir?, modal?} (@radix-ui/react-context-menu@2.3.1 dist/index.d.mts:8-14). The defaultOpen?: boolean at line 68 of that file belongs to ContextMenuSubProps, which this wrapper does not touch.
Nothing in the tree passes defaultOpen to <ContextMenu> (grep over website/src). Honouring a prop the primitive does not define would invent a contract, not restore one.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Head 57eef3998: ContextMenu wrapper trimmed to its uncontrolled form (prop type omits open), useCloseOnFileDrag writes its ref in an effect, rebased onto main a992d5cd. No other code change.

Note for the record: the Fork Opus 5 Review run for 7203a7a2c (36070449918) completed discovery and validation but could not post its summary because the CI app's installation API rate limit was exhausted (gh: API rate limit exceeded for installation, six retries in Post/update summary comment). The new head re-runs it.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Bundle Size Gate on 57eef3998 is inherited from main, not this diff:

  • Local reproduction: assets/all-*.js is 2.8 KB over the 12870 KB budget in website/scripts/check-bundle-size.mjs (its comment records 12254.6 KB measured on main @ 34fe0de, 2026-09-21; main has grown ~615 KB since).
  • fix(channels): grade the rotation boundary the splitter cannot see #13494 (fix/rotation-seam-credential-12293, 0 of 6 files under website/) fails the same gate on the same main, run 36074273162; so does feat/layout-model (run 36073769832).
  • This PR adds one 36-line hook and trims a wrapper; it cannot account for the overflow, and raising CHUNK_BUDGETS.all here would be out of scope.

Holding for the budget fix on main; will rebase once it lands.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Unverified end-to-end behaviour on the only path that matters — fixed: attested real-browser run of this revision added to the PR body

Chromium against a harness gateway serving this head's dist; the drag is produced with CDP Input.dispatchDragEvent, which goes through real hit-testing and so honours body pointer-events: none exactly as an OS drag does.
Observed on 57eef3998: menu open -> body pointer-events: none; file dragEnter at the window edge -> menu unmounted, body auto; dragOver composer -> drop overlay mounted; drop -> hello.txt chip attached. Screenshots and result.json in the body (Screenshots / video).
Control on main a992d5cd with the identical script: menu stays mounted, body stays none, no overlay, nothing attached (screenshots in the body's <details>).
Evidence lives in an immutable fork media ref (refs/media/pr-13541 @ f156d01); a fork contributor cannot use gh --attach.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Only the menu primitives are wrapped; modal Popover/Select sites remain — rebutted as out of scope, sites listed

The intent comment fixes the scope to menus; the PR's "Not a goal" line already excludes other layers. The remaining modal Radix sites are components/AgentSelector.tsx (modal prop, default false, opted in only when it renders inside a dialog), components/AgentSkillsEditor.tsx:232 and a Select inside apps/issue-radar/components/CrewEditor.tsx:737.
All three are opened inside a modal Dialog, which already covers the composer and blocks the drop on its own; closing the inner popover would not make the drop reachable. That is a different fix (dismissing the dialog) with a different UX question, not a missing sibling of this one.
Follow-up, if wanted: apply useCloseOnFileDrag to the Popover wrapper once a caller opens a modal popover outside a dialog; today none does.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author
  • Radix ContextMenu.Root has no open prop, so the ContextMenu close is inert and tsc fails — rebutted: not a defect; the premise is false against the installed package

@radix-ui/react-context-menu@2.3.1 (the version in website/node_modules) declares ContextMenuProps { children?, open?: boolean, onOpenChange?, dir?, modal? } at dist/index.d.mts:8-14, and Root reads it: const { ..., onOpenChange, open: openProp, dir, modal = true } = props (dist/index.mjs:19) into useControllableState({ prop: openProp, defaultProp: false, onChange: onOpenChange }) (dist/index.mjs:32-36). open={false} from the wrapper therefore closes the Radix menu.
tsc does not fail: Frontend Lint & Type Check is green on this head (CI run for d6efc5311) and on every prior head; Omit<ComponentProps<typeof Root>, 'open'> compiles precisely because open is a Root prop.
website/integration/__mocks__/@radix-ui/react-context-menu.tsx is a hand-written test double that two FileExplorer tests opt into with vi.mock; it is not the library's API and no other test uses it. The ContextMenu dismissal tests in DropdownMenu.fileDragClose.test.tsx run against the real package and pass; the real-Chromium run in the body (harness gateway + CDP drag) shows the same close path working end to end.
The proposed fix (restore the bare Root) would reintroduce the reported bug for right-click menus on sidebar rows, the exact site the Design lane asked to cover in round 1.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

@NicholasRBowers one ask, when you have a minute: head d6efc5311 is green on every CI check and on the Design, First Principles, UX and GPT lanes. The only red is the fork Opus lane, whose blocking finding says Radix ContextMenu.Root has no open prop and that tsc fails. Both are false for the installed @radix-ui/react-context-menu@2.3.1 (open?: boolean at dist/index.d.mts:10, wired through useControllableState at dist/index.mjs:32); Frontend Lint & Type Check is green on this head, and the ContextMenu close path is exercised by website/src/test/DropdownMenu.fileDragClose.test.tsx against the real package plus the Chromium run in the body. Details in the disposition comment above (span 12666f276e96). A rebuttal cannot clear that lane; if you agree, this records the decision and re-runs it:

/ai-review override fable d6efc5311f17a2c26cb513dd989124b67a6d228e: Radix ContextMenu Root 2.3.1 exposes a controlled open prop (dist/index.d.mts:10); tsc is green; finding is a false positive.

I will not re-ping; the PR otherwise needs nothing from anyone.

@Pearcekieser
Pearcekieser force-pushed the fix/sidebar-menu-blocks-file-drop branch from d6efc53 to d202127 Compare September 27, 2026 04:43
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (b1de40b -> e4e6ed7), same code, one commit: d6efc53 -> d202127. No code change; the push reruns every lane so the Opus fork lane and readiness re-judge a fresh head. Targeted tests: website/src/test/DropdownMenu.fileDragClose.test.tsx 7/7 pass.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 27, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/sidebar-menu-blocks-file-drop branch from d202127 to b5e3f67 Compare September 27, 2026 07:39
@Pearcekieser
Pearcekieser requested a review from a team as a code owner September 27, 2026 07:39
@Pearcekieser
Pearcekieser requested review from cruisercohen and removed request for cixuuz September 27, 2026 07:39
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (e4e6ed7 -> 75b52f1), same code, one commit: d202127 -> b5e3f67. No code change. Round 5's Fork Opus lane (run 36295526281) died on the CI app's installation rate limit before posting a verdict, so this push re-rolls the lanes. Targeted tests: website/src/test/DropdownMenu.fileDragClose.test.tsx 7/7 pass.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 27, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/sidebar-menu-blocks-file-drop branch from b5e3f67 to 69a4ed0 Compare September 27, 2026 08:47
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

Retrigger push b5e3f67 -> 69a4ed0: identical tree (timestamp-only amend), no code change. Round 6 on b5e3f67 passed every CI check and the GPT, Opus, Design, First Principles and Security lanes; the UX lane blocked only because the four evidence screenshots were raw fork-commit URLs its evidence step no longer admits. The PR body now embeds them as GitHub user-attachments URLs; this push lets the UX lane re-judge.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Sep 27, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 27, 2026 17:32
@iamwhatever
iamwhatever merged commit 3389bd8 into kirodotdev:main Sep 27, 2026
100 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Open sidebar menu blocks dropping a file into the chat

2 participants