Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): worktree row opens the flyout on click (name still opens project) (#2522)

Andrew Mikofalvy974e123fd7b5
diff --git a/packages/app/src/components/RecentProjectsMenu.dom.test.tsx b/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
index 1b7ede0c9..8de8b9f0e 100644
--- a/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
+++ b/packages/app/src/components/RecentProjectsMenu.dom.test.tsx
@@ -65,9 +65,10 @@ mock.module('@/components/ui/dropdown-menu', () => ({
}) => {
const { onOpenChange } = use(SubStateContext);
// Model Radix's SubTrigger composition: our handler runs first, and Radix
- // opens the sub only if we did NOT preventDefault. The component's onClick /
- // Enter+Space preventDefault (they navigate to the project instead), so those
- // do NOT open the flyout; hover and ArrowRight still do.
+ // opens the sub only if we did NOT preventDefault. The component preventDefaults
+ // a click on the project-name target (data-project-open) and Enter / Space, to
+ // open the project instead — so those do NOT open the flyout; a click elsewhere
+ // on the row, hover, and ArrowRight open the flyout; ArrowLeft / Escape close it.
return (
<div
role="menuitem"
@@ -249,7 +250,7 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
expect(row.querySelector('svg')).toBeNull();
});
- test('clicking a worktree-bearing row opens the PROJECT (root) directly, not the flyout', async () => {
+ test('clicking the row body (not the name) opens the worktree flyout, not the project', async () => {
const { bridge } = renderMenu({
recents: [
main('/repo', '/repo/.git'),
@@ -270,9 +271,35 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
expect(toggle.textContent).toContain('1 worktree');
expect(toggle.textContent).not.toContain('1 worktrees');
- // Two-target row: a direct CLICK opens the bare project (root) in one click,
- // and does NOT open the flyout (the click preventDefaults Radix's open).
- fireEvent.click(screen.getByTestId('project-switcher-group-/repo'));
+ // Two-target row: clicking a NON-name part of the row (here the count chip)
+ // opens the submenu (flyout) — the big, easy target — and does NOT open the
+ // project. Radix's SubTrigger opens the sub on click because the handler only
+ // preventDefaults for the name target (see the next test).
+ fireEvent.click(toggle);
+ await waitFor(() => {
+ expect(screen.getByTestId('project-switcher-flyout-/repo')).not.toBeNull();
+ });
+ expect(bridge.project.open).not.toHaveBeenCalled();
+ });
+
+ test('clicking the project name opens the project (root) directly, not the flyout', async () => {
+ const { bridge } = renderMenu({
+ recents: [
+ main('/repo', '/repo/.git'),
+ worktree('/repo/.ok/worktrees/dev', '/repo/.git', '/repo', 'dev'),
+ ],
+ });
+ const groupRow = screen.getByTestId('project-switcher-group-/repo');
+ expect(screen.queryByTestId('project-switcher-flyout-/repo')).toBeNull();
+
+ // The project name is the direct open-project target (tagged
+ // data-project-open); the row's onClick routes name-clicks to the project.
+ const nameTarget = groupRow.querySelector('[data-project-open]');
+ expect(nameTarget?.textContent).toBe('repo');
+
+ // Name-click opens the bare project (root) in one click, and does NOT also
+ // open the flyout — the click preventDefaults Radix's open (no double-fire).
+ fireEvent.click(nameTarget as Element);
await waitFor(() => {
expect(bridge.project.open).toHaveBeenCalledWith({
path: '/repo',
@@ -331,8 +358,9 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
const row = screen.getByTestId('project-switcher-group-/repo');
expect(screen.queryByTestId('project-switcher-flyout-/repo')).toBeNull();
- // ArrowRight (the count-chip trigger is out of roving focus) opens the flyout
- // from the focused row — without opening the project.
+ // ArrowRight is the standard submenu key and is not intercepted, so it opens
+ // the flyout from the focused row — without opening the project (Enter/Space
+ // open the project instead; see the two-target test above).
fireEvent.keyDown(row, { key: 'ArrowRight' });
await waitFor(() => {
expect(screen.getByTestId('project-switcher-flyout-/repo')).not.toBeNull();
@@ -374,7 +402,8 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
const row = screen.getByTestId('project-switcher-group-/repo');
// Enter opens the bare project (the SUB_OPEN key is preventDefaulted so Radix
- // does not open the submenu instead) and leaves the flyout closed.
+ // does not open the submenu instead) and leaves the flyout closed — matching
+ // the name being the primary target. ArrowRight (below) opens the submenu.
fireEvent.keyDown(row, { key: 'Enter' });
await waitFor(() => {
expect(bridge.project.open).toHaveBeenCalledWith({
@@ -684,9 +713,9 @@ describe('RecentProjectsMenu — grouped browse (no query)', () => {
});
test('the flyout’s pinned "default" entry also opens the project root (secondary path to the same action)', async () => {
- // Row-click is the primary one-click open (covered above); the repo's
- // default/main checkout is also the pinned first flyout entry, opening the
- // same bare root with the `recents` entry point.
+ // Clicking the project name is the primary one-click open (covered above);
+ // the repo's default/main checkout is also the pinned first flyout entry,
+ // opening the same bare root with the `recents` entry point.
const { bridge } = renderMenu({
recents: [
main('/repo', '/repo/.git'),
diff --git a/packages/app/src/components/RecentProjectsMenu.tsx b/packages/app/src/components/RecentProjectsMenu.tsx
index 7db0e33b8..7e5291524 100644
--- a/packages/app/src/components/RecentProjectsMenu.tsx
+++ b/packages/app/src/components/RecentProjectsMenu.tsx
@@ -304,17 +304,29 @@ function FlyoutGroup({
const { t } = useLingui();
const projectIsCurrent = group.project.path === currentPath;
- // Two-target row on a real submenu (restores the pre-migration ergonomics):
- // - HOVER anywhere on the row opens the worktree flyout (native Radix
- // safe-triangle + close-on-leave-both), and ArrowRight opens it by keyboard.
- // - CLICK / Enter / Space open the PROJECT (its root) directly — one click,
- // same as a flat row. Radix's SubTrigger opens the submenu on click and on
- // the SUB_OPEN_KEYS (Enter/Space/ArrowRight); it bails when our handler
- // already called preventDefault (onClick: `if (event.defaultPrevented) return`;
- // onKeyDown: composed with checkForDefaultPrevented), so preventing default
- // on click + Enter/Space suppresses the open and lets navigation win while
- // ArrowRight still falls through to open the flyout. guardStaleSelect
- // swallows the Electron menu-open click fall-through, as on the flat rows.
+ // Two-target worktree row on a real submenu (restores #2339's "the name opens
+ // the project, the rest expands"), fixing the hover-only discoverability gap
+ // from #2473 (which intercepted every click to open the project, so there was
+ // no click path to the submenu):
+ // - CLICK the project NAME (tagged [data-project-open]) opens the bare
+ // project root. CLICK anywhere else on the row opens the worktree flyout.
+ // Radix's SubTrigger opens the (controlled) sub on click UNLESS our handler
+ // preventDefaults, so the onClick only preventDefaults + opens the project
+ // when the click landed on the name target; every other click falls through
+ // to Radix and opens the flyout. The name is a passive [data-project-open]
+ // click-zone, NOT its own interactive element — the handler lives on the
+ // Radix SubTrigger (a real role="menuitem"), so there is no nested
+ // <span onClick> and no extra focus stop.
+ // - HOVER anywhere on the row opens the flyout (native Radix safe-triangle +
+ // close-on-leave-both).
+ // - KEYBOARD (row focused): Enter / Space open the PROJECT — matching the
+ // name being the primary target — so we preventDefault to suppress Radix's
+ // SUB_OPEN of the flyout, then open. ArrowRight still falls through to Radix
+ // to open the flyout (the standard submenu key), and ArrowLeft / Escape
+ // close it. Redefining Enter/Space's action (rather than removing keyboard
+ // nav) keeps the submenu keyboard-reachable via ArrowRight.
+ // guardStaleSelect swallows the Electron menu-open click fall-through on the
+ // project-open path, as on the flat rows.
const openProjectFromRow = (nativeEvent: Event): void => {
if (guardStaleSelect(nativeEvent)) return;
onPickProject();
@@ -323,10 +335,17 @@ function FlyoutGroup({
<DropdownMenuSub open={flyoutOpen} onOpenChange={setFlyoutOpen}>
<DropdownMenuSubTrigger
onClick={(e) => {
+ // Only a click on the project-name target opens the project; every
+ // other click falls through to Radix and opens the flyout. `e.target`
+ // may be an SVGElement (the current-project check icon), so cast to the
+ // Element interface `.closest` lives on rather than HTMLElement.
+ if ((e.target as Element).closest('[data-project-open]') === null) return;
e.preventDefault();
openProjectFromRow(e.nativeEvent);
}}
onKeyDown={(e) => {
+ // Enter / Space open the project (the name's action); ArrowRight is
+ // left to Radix to open the flyout.
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
openProjectFromRow(e.nativeEvent);
@@ -341,7 +360,15 @@ function FlyoutGroup({
disambiguates same-named checkouts. No folder icon: the switcher stays
focused on project names, reclaiming the horizontal space. */}
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
- <span className="truncate font-medium text-sm" title={group.project.name}>
+ {/* The project name is the direct open-project target: a passive
+ click-zone the row's onClick routes on via [data-project-open]. Every
+ other part of the row (the path line, the count chip, empty space)
+ opens the worktree flyout instead. */}
+ <span
+ className="truncate font-medium text-sm"
+ data-project-open=""
+ title={group.project.name}
+ >
{group.project.name}
</span>
<span className="truncate text-muted-foreground text-xs" title={group.project.path}>