From 3400ffc9dca5e7a8ddfa416006cb626f80a375fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Thu, 28 May 2026 21:34:16 +0800 Subject: [PATCH] feat: optimize TopBar search with Cmd+K shortcut and improved styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add global Cmd/Ctrl+K keyboard shortcut to focus search input - Show keyboard shortcut hint (⌘K) in search input when empty - Improve input styling: rounded-lg, softer borders, focus transitions - Improve dropdown: rounded-lg, larger shadow, better spacing - Larger result icons (h-8 w-8) with rounded-lg containers - Refined history section with uppercase label and muted icon - Search icon fades in on focus via group-focus-within Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/components/TopBar.tsx | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index e9cdba9..99f15c6 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -49,6 +49,19 @@ export default function TopBar({ onOpenOptions }: { onOpenOptions: () => void }) return () => document.removeEventListener('mousedown', handleClickOutside); }, []); + // Cmd/Ctrl+K 快捷键聚焦搜索框 + useEffect(() => { + const handleGlobalKeyDown = (e: KeyboardEvent) => { + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + inputRef.current?.focus(); + setShowResults(true); + } + }; + document.addEventListener('keydown', handleGlobalKeyDown); + return () => document.removeEventListener('keydown', handleGlobalKeyDown); + }, []); + useEffect(() => { storageUtil .get('app/searchHistory', []) @@ -153,8 +166,8 @@ export default function TopBar({ onOpenOptions }: { onOpenOptions: () => void }) {/* 中间:搜索容器 */}
-
- +
+ void }) onFocus={() => setShowResults(true)} onKeyDown={handleKeyDown} aria-label={t('common_buttons_search')} - className="w-full h-9 pl-9 pr-8 text-sm rounded-md border border-input bg-muted/50 transition-all placeholder:text-muted-foreground focus:bg-background focus:outline-none focus:ring-1 focus:ring-ring focus:border-input" + className="w-full h-9 pl-9 pr-16 text-sm rounded-lg border border-border/60 bg-muted/40 transition-all placeholder:text-muted-foreground/50 focus:bg-background focus:outline-none focus:ring-1 focus:ring-ring focus:border-input" /> + {!searchQuery && ( + + ⌘K + + )} {searchQuery && (