Skip to content

Commit

Permalink
press enter to submit chat prompt (#2537)
Browse files Browse the repository at this point in the history
close #2518
  • Loading branch information
notmd committed Apr 15, 2023
1 parent a1fa75f commit a2a0850
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion website/src/components/Chat/ChatForm.tsx
@@ -1,6 +1,6 @@
import { Button, Grid, Textarea } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";
import { forwardRef, SyntheticEvent, useCallback } from "react";
import { forwardRef, KeyboardEvent, SyntheticEvent, useCallback } from "react";
import TextareaAutosize from "react-textarea-autosize";
import { QueueInfo } from "src/lib/chat_stream";

Expand All @@ -24,6 +24,14 @@ export const ChatForm = forwardRef<HTMLTextAreaElement, ChatFormProps>((props, r
},
[onSubmit]
);
const handleKeydown = useCallback(
(e: KeyboardEvent) => {
if (e.key === "Enter") {
onSubmit();
}
},
[onSubmit]
);
return (
<form onSubmit={handleSubmit}>
<Textarea
Expand All @@ -32,6 +40,7 @@ export const ChatForm = forwardRef<HTMLTextAreaElement, ChatFormProps>((props, r
bg="gray.100"
borderRadius="xl"
isDisabled={isSending}
onKeyDown={handleKeydown}
_dark={{
bg: "gray.800",
}}
Expand Down

0 comments on commit a2a0850

Please sign in to comment.