From acb5d928f974babcf1f8f96f1489830bfb3bae43 Mon Sep 17 00:00:00 2001 From: Florian Maas Date: Sun, 23 Jun 2024 16:57:09 +0200 Subject: [PATCH] Start search when user presses enter --- frontend/app/page.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 205f5f4..2e5d3a9 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -31,6 +31,20 @@ export default function Home() { setResults(sortResults(results, field, direction)); }; + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + handleSearch( + text, + sortField, + sortDirection, + setResults, + setLoading, + setError, + ); + } + }; + return (
@@ -55,6 +69,7 @@ export default function Home() { className="placeholder-gray-400 w-full h-24 p-2 border border-sky-900 rounded resize-none overflow-auto focus:outline-none focus:ring-2 focus:ring-sky-800 bg-white text-sky-950" value={text} onChange={(e) => setText(e.target.value)} + onKeyDown={handleKeyDown} placeholder="Describe what you are looking for... " >