Skip to content

Commit a2a0850

Browse files
authored
press enter to submit chat prompt (#2537)
close #2518
1 parent a1fa75f commit a2a0850

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

website/src/components/Chat/ChatForm.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button, Grid, Textarea } from "@chakra-ui/react";
22
import { useTranslation } from "next-i18next";
3-
import { forwardRef, SyntheticEvent, useCallback } from "react";
3+
import { forwardRef, KeyboardEvent, SyntheticEvent, useCallback } from "react";
44
import TextareaAutosize from "react-textarea-autosize";
55
import { QueueInfo } from "src/lib/chat_stream";
66

@@ -24,6 +24,14 @@ export const ChatForm = forwardRef<HTMLTextAreaElement, ChatFormProps>((props, r
2424
},
2525
[onSubmit]
2626
);
27+
const handleKeydown = useCallback(
28+
(e: KeyboardEvent) => {
29+
if (e.key === "Enter") {
30+
onSubmit();
31+
}
32+
},
33+
[onSubmit]
34+
);
2735
return (
2836
<form onSubmit={handleSubmit}>
2937
<Textarea
@@ -32,6 +40,7 @@ export const ChatForm = forwardRef<HTMLTextAreaElement, ChatFormProps>((props, r
3240
bg="gray.100"
3341
borderRadius="xl"
3442
isDisabled={isSending}
43+
onKeyDown={handleKeydown}
3544
_dark={{
3645
bg: "gray.800",
3746
}}

0 commit comments

Comments
 (0)