Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): project switcher opens and dismisses in desktop app (#1626)
Andrew Mikofalvya607900409a8
diff --git a/.changeset/fix-project-switcher-click-open-dismiss.md b/.changeset/fix-project-switcher-click-open-dismiss.mdnew file mode 100644index 000000000..178b09c27--- /dev/null+++ b/.changeset/fix-project-switcher-click-open-dismiss.md@@ -0,0 +1,9 @@+---+"@inkeep/open-knowledge": patch+"@inkeep/open-knowledge-core": patch+"@inkeep/open-knowledge-server": patch+"@inkeep/open-knowledge-app": patch+"@inkeep/open-knowledge-desktop": patch+---++Fix the sidebar project switcher not opening, and not dismissing on outside click, in the macOS desktop app. Radix's DropdownMenu opens on `pointerdown`, but the desktop renderer does not receive real `pointerdown` events (only `mousedown`/`click`), so clicking the trigger did nothing; and because the menu was modal, clicking outside could not dismiss it either. The trigger now also opens from the `click` event on the desktop host (mirroring the editor's "Open with AI" menu), and the menu is non-modal so outside-click dismissal works and the rest of the UI stays interactive while it's open — matching the Cloud/Sync popover. Browsers are unaffected.diff --git a/packages/app/src/components/ProjectSwitcher.test.ts b/packages/app/src/components/ProjectSwitcher.test.tsindex 02a15d246..88ba34271 100644--- a/packages/app/src/components/ProjectSwitcher.test.ts+++ b/packages/app/src/components/ProjectSwitcher.test.ts@@ -208,17 +208,14 @@ describe('Recent-projects search affordance (source-level guards)', () => {});});-describe('macOS dropdown-open regression guard (no Radix Tooltip on the trigger)', () => {+describe('macOS dropdown-open regression guard (click-to-open fallback)', () => {const SRC_PATH = join(__dirname, 'ProjectSwitcher.tsx');const src = readFileSync(SRC_PATH, 'utf-8');- test('trigger is not wrapped in a Radix Tooltip; project path uses native title', () => {- expect(src).not.toContain("from '@/components/ui/tooltip'");- expect(src).not.toMatch(/<TooltipTrigger\b/);- const triggerTag = src.match(- /<SidebarMenuButton\b[\s\S]*?data-testid="project-switcher-trigger"[\s\S]*?>/,- )?.[0];- expect(triggerTag, 'project switcher trigger button not found').toBeTruthy();- expect(triggerTag).toMatch(/title=\{bridge\.config\.projectPath\}/);+ test('trigger opens from onClick on the Electron host, with a pointerdown guard', () => {+ expect(src).toMatch(/onClick=\{\s*isElectronHost/);+ expect(src).toMatch(/onPointerDown=\{\s*isElectronHost/);+ expect(src).toContain('sawPointerDownRef');+ expect(src).toMatch(/<DropdownMenu\b[^>]*\bmodal=\{false\}/);});});diff --git a/packages/app/src/components/ProjectSwitcher.tsx b/packages/app/src/components/ProjectSwitcher.tsxindex bb16adfeb..fa6fe14fb 100644--- a/packages/app/src/components/ProjectSwitcher.tsx+++ b/packages/app/src/components/ProjectSwitcher.tsx@@ -1,6 +1,6 @@import { Trans, useLingui } from '@lingui/react/macro';import { ChevronsUpDown, FolderOpen, GitBranch, LayoutGrid, Plus, Search } from 'lucide-react';-import { useEffect, useState } from 'react';+import { useEffect, useRef, useState } from 'react';import {DropdownMenu,DropdownMenuContent,@@ -35,6 +35,14 @@ export function ProjectSwitcher({ bridge }: ProjectSwitcherProps) {const [createProjectOpen, setCreateProjectOpen] = useState(false);const branch = useCurrentBranch();+ const isElectronHost = typeof window !== 'undefined' && window.okDesktop != null;+ const sawPointerDownRef = useRef(false);++ const handleOpenChange = (next: boolean): void => {+ setOpen(next);+ if (!next) setSearch('');+ };+useEffect(() => {if (!open) return;let cancelled = false;@@ -86,25 +94,17 @@ export function ProjectSwitcher({ bridge }: ProjectSwitcherProps) {return (<>- <DropdownMenu- open={open}- onOpenChange={(next) => {- setOpen(next);- if (!next) setSearch('');- }}- >- {/*- Bare trigger — do NOT wrap in a Radix <Tooltip>. The project path is- surfaced via the native `title` attribute instead. A Radix Tooltip- here breaks the dropdown: once the tooltip has opened on hover,- clicking the trigger races the tooltip layer's pointerdown-teardown- against the dropdown's open on the macOS desktop host, and the menu- never stays open (the trigger shows its click state but nothing- opens). The native title has no layer to tear down, so the dropdown- opens cleanly. This is the mirror of the EditorHeader Open-with-AI- trigger, which is bare for the same class of pointer-interaction- reason.- */}+ {/*+ Non-modal (matches the Cloud/Sync Popover, which is non-modal and works+ normally). In the macOS desktop app, outside-click dismissal relies on a+ `pointerdown` Chromium does not deliver here (see the trigger onClick+ below), and a modal dropdown additionally disables pointer events on the+ rest of the chrome while open — together that left the menu impossible+ to dismiss by clicking out. Non-modal keeps the rest of the UI live and+ restores outside-click dismissal; the menu still closes on item-select,+ Escape, or re-clicking the trigger.+ */}+ <DropdownMenu open={open} onOpenChange={handleOpenChange} modal={false}><DropdownMenuTrigger asChild><SidebarMenuButtonclassName={cn(@@ -114,6 +114,24 @@ export function ProjectSwitcher({ bridge }: ProjectSwitcherProps) {data-testid="project-switcher-trigger"aria-label={t`Open project menu`}title={bridge.config.projectPath}+ onPointerDown={+ isElectronHost+ ? () => {+ sawPointerDownRef.current = true;+ }+ : undefined+ }+ onClick={+ isElectronHost+ ? () => {+ if (sawPointerDownRef.current) {+ sawPointerDownRef.current = false;+ return;+ }+ handleOpenChange(!open);+ }+ : undefined+ }><span className="flex min-w-0 flex-col gap-0.5"><span className="truncate">{bridge.config.projectName}</span>