feat: add global escape key handling to close search modal
This commit is contained in:
@@ -159,6 +159,20 @@ export function GlobalSearch({ isOpen, onClose }: GlobalSearchProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle global escape key
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen) return
|
||||||
|
|
||||||
|
const handleGlobalKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleGlobalKeyDown)
|
||||||
|
return () => window.removeEventListener('keydown', handleGlobalKeyDown)
|
||||||
|
}, [isOpen, onClose])
|
||||||
|
|
||||||
if (!isOpen) return null
|
if (!isOpen) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -193,8 +207,8 @@ export function GlobalSearch({ isOpen, onClose }: GlobalSearchProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Results */}
|
{/* Results */}
|
||||||
<ScrollArea className="max-h-[60vh]">
|
<ScrollArea className="h-[60vh]">
|
||||||
<div className="p-2 max-h-[60vh] overflow-y-auto">
|
<div className="p-2">
|
||||||
{loading && (
|
{loading && (
|
||||||
<div className="p-4 text-center text-muted-foreground">
|
<div className="p-4 text-center text-muted-foreground">
|
||||||
Searching...
|
Searching...
|
||||||
|
|||||||
Reference in New Issue
Block a user