mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-28 16:06:28 +01:00
fix: chat input keyDown (#64)
This commit is contained in:
@@ -3,13 +3,14 @@ import { useEffect, useRef, useImperativeHandle, forwardRef } from "react";
|
||||
interface AutoResizeTextareaProps {
|
||||
input: string;
|
||||
setInput: (value: string) => void;
|
||||
handleKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
||||
}
|
||||
|
||||
// Forward ref to allow parent to interact with this component
|
||||
const AutoResizeTextarea = forwardRef<
|
||||
{ reset: () => void; focus: () => void },
|
||||
AutoResizeTextareaProps
|
||||
>(({ input, setInput }, ref) => {
|
||||
>(({ input, setInput, handleKeyDown }, ref) => {
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -41,6 +42,7 @@ const AutoResizeTextarea = forwardRef<
|
||||
placeholder="Ask whatever you want ..."
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
rows={1}
|
||||
style={{
|
||||
resize: "none", // Prevent manual resize
|
||||
|
||||
@@ -106,6 +106,12 @@ export default function ChatInput({
|
||||
ref={textareaRef}
|
||||
input={inputValue}
|
||||
setInput={changeInput}
|
||||
handleKeyDown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
handleSubmit();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user