Merge pull request #4 from PeterTakahashi/fix/support-japanese-typing

fix: support japanese typing
This commit is contained in:
Mckay Wrigley 2023-03-17 18:24:25 -06:00 committed by GitHub
commit 506b5c1684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -8,6 +8,7 @@ interface Props {
export const ChatInput: FC<Props> = ({ onSend }) => { export const ChatInput: FC<Props> = ({ onSend }) => {
const [content, setContent] = useState<string>(); const [content, setContent] = useState<string>();
const [isTyping, setIsTyping] = useState<boolean>(false);
const textareaRef = useRef<HTMLTextAreaElement>(null); const textareaRef = useRef<HTMLTextAreaElement>(null);
@ -31,7 +32,7 @@ export const ChatInput: FC<Props> = ({ onSend }) => {
}; };
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => { const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === "Enter" && !e.shiftKey) { if (!isTyping && e.key === "Enter" && !e.shiftKey) {
e.preventDefault(); e.preventDefault();
handleSend(); handleSend();
} }
@ -54,6 +55,8 @@ export const ChatInput: FC<Props> = ({ onSend }) => {
placeholder="Type a message..." placeholder="Type a message..."
value={content} value={content}
rows={1} rows={1}
onCompositionStart={() => setIsTyping(true)}
onCompositionEnd={() => setIsTyping(false)}
onChange={handleChange} onChange={handleChange}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
/> />