fix: chat input keyDown (#64)

This commit is contained in:
BiggerRain
2024-12-23 10:25:04 +08:00
committed by GitHub
parent f61bb279e0
commit d73fe46699
2 changed files with 9 additions and 1 deletions

View File

@@ -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

View File

@@ -106,6 +106,12 @@ export default function ChatInput({
ref={textareaRef}
input={inputValue}
setInput={changeInput}
handleKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
handleSubmit();
}
}}
/>
) : (
<input