diff --git a/packages/ui/src/components/chat/PendingChangesBar.tsx b/packages/ui/src/components/chat/PendingChangesBar.tsx index 9d4bb806..656341b0 100644 --- a/packages/ui/src/components/chat/PendingChangesBar.tsx +++ b/packages/ui/src/components/chat/PendingChangesBar.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { Popover } from '@base-ui/react/popover'; import { useDirectoryStore } from '@/stores/useDirectoryStore'; import { useGitStore, useIsGitRepo } from '@/stores/useGitStore'; import { useUIStore } from '@/stores/useUIStore'; @@ -7,6 +6,7 @@ import { RuntimeAPIContext } from '@/contexts/runtimeAPIContext'; import { sessionEvents } from '@/lib/sessionEvents'; import { normalizePath } from '@/components/session/sidebar/utils'; import { Icon } from "@/components/icon/Icon"; +import { cn } from '@/lib/utils'; import { type ChangedFileEntry, type GitChangedFile, @@ -20,6 +20,7 @@ import { useI18n } from '@/lib/i18n'; export const PendingChangesBar: React.FC = React.memo(() => { const { t } = useI18n(); const [isExpanded, setIsExpanded] = React.useState(false); + const popoverRef = React.useRef(null); const currentDirectory = useDirectoryStore((s) => s.currentDirectory); const runtime = React.useContext(RuntimeAPIContext); const isGitRepo = useIsGitRepo(currentDirectory); @@ -29,6 +30,20 @@ export const PendingChangesBar: React.FC = React.memo(() => { const ensureStatus = useGitStore((s) => s.ensureStatus); const fetchStatus = useGitStore((s) => s.fetchStatus); + // Close popover when clicking outside + React.useEffect(() => { + if (!isExpanded) return; + + const handleClickOutside = (event: MouseEvent) => { + if (popoverRef.current && !popoverRef.current.contains(event.target as Node)) { + setIsExpanded(false); + } + }; + + document.addEventListener("mousedown", handleClickOutside); + return () => document.removeEventListener("mousedown", handleClickOutside); + }, [isExpanded]); + // Seed git store for currentDirectory so the bar can render independently of // DiffView/GitView/right-sidebar mounting. ensureStatus has a 5s staleness // gate and inFlightStatusFetchesByDirectory dedupes against concurrent callers. @@ -96,45 +111,49 @@ export const PendingChangesBar: React.FC = React.memo(() => { : t('chat.pendingChanges.fileCountPlural', { count: fileCount }); return ( - - - - {labelHead} - - {t('chat.pendingChanges.changedInWorkspace')} - - - {totalAdded > 0 ? +{totalAdded} : null} - {totalRemoved > 0 ? -{totalRemoved} : null} - - {isExpanded ? ( - - ) : ( - - )} - - } - /> - - - - - - - - +
+ + {isExpanded && ( +
+ +
+ )} +
); });