From a3ea23ebd7da7a6a6f95343fcd1cad0effd8e2e3 Mon Sep 17 00:00:00 2001
From: YasinOnm08 <onmazyasin4@gmail.com>
Date: Thu, 19 Sep 2024 16:52:16 +0200
Subject: [PATCH] Enter works again

---
 app/InputFrontend.tsx | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/app/InputFrontend.tsx b/app/InputFrontend.tsx
index c3cdea8..cf9dffc 100644
--- a/app/InputFrontend.tsx
+++ b/app/InputFrontend.tsx
@@ -14,19 +14,28 @@ const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
       setInputValue(e.target.value);
     };
 
+    const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+      if (event.key === 'Enter') {
+        onSendClick(inputValue); // Call the function passed via props
+        setInputValue(''); // Optionally clear input after submission
+        event.preventDefault(); // Prevent default action (e.g., form submission)
+      }
+    };
+
     return (
-      <div className="input" id="inputForm">
+      <div className="input" id="inputForm" ref={ref}>
         <input
           type="text"
           name="user_message"
           placeholder="Type your message here..."
           value={inputValue}
           onChange={handleInputChange}
+          onKeyDown={handleKeyDown}
         />
-        <button type="submit" onClick={() => onSendClick(inputValue)}>
+        <button type="button" onClick={() => onSendClick(inputValue)}>
           <img src="/img/send.svg" alt="send" />
         </button>
-        <button type="submit" onClick={onMicClick}>
+        <button type="button" onClick={onMicClick}>
           <img src="/img/microphone.svg" alt="microphone" />
         </button>
       </div>