From 3ba74d99fbcc965092b5a2bc898b2216383fc6a4 Mon Sep 17 00:00:00 2001 From: PeterTakahashi Date: Sat, 18 Mar 2023 08:31:37 +0900 Subject: [PATCH] fix: support japanese typing --- components/Chat/ChatInput.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index cf9f460..234b62e 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -8,6 +8,7 @@ interface Props { export const ChatInput: FC = ({ onSend }) => { const [content, setContent] = useState(); + const [isTyping, setIsTyping] = useState(false); const textareaRef = useRef(null); @@ -31,7 +32,7 @@ export const ChatInput: FC = ({ onSend }) => { }; const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === "Enter" && !e.shiftKey) { + if (!isTyping && e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSend(); } @@ -54,6 +55,8 @@ export const ChatInput: FC = ({ onSend }) => { placeholder="Type a message..." value={content} rows={1} + onCompositionStart={() => setIsTyping(true)} + onCompositionEnd={() => setIsTyping(false)} onChange={handleChange} onKeyDown={handleKeyDown} />