From 7337889de9e80e367c8c03fc1cbf1055ebcf36ee Mon Sep 17 00:00:00 2001 From: nbramblett Date: Thu, 16 May 2024 13:06:10 -0400 Subject: [PATCH] Patch input to handle Enter event for japanese keyboards correctly --- package-lock.json | 4 ++-- package.json | 2 +- src/components/ChatInput.tsx | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index b44341a..7efd952 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/chat-ui-react", - "version": "0.9.2", + "version": "0.9.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@yext/chat-ui-react", - "version": "0.9.2", + "version": "0.9.3", "license": "BSD-3-Clause", "dependencies": { "react-markdown": "^6.0.3", diff --git a/package.json b/package.json index 2efcfbf..294293a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/chat-ui-react", - "version": "0.9.2", + "version": "0.9.3", "description": "A library of React Components for powering Yext Chat integrations.", "author": "clippy@yext.com", "main": "./lib/commonjs/src/index.js", diff --git a/src/components/ChatInput.tsx b/src/components/ChatInput.tsx index 3a2cc91..b72e533 100644 --- a/src/components/ChatInput.tsx +++ b/src/components/ChatInput.tsx @@ -106,7 +106,12 @@ export function ChatInput({ const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { - if (!e.shiftKey && e.key === "Enter") { + if (!e.shiftKey && e.key === "Enter" && + // The Japanese Keyboard uses "Enter" key to convert from Hiragana to Kanji. + // "isComposing" is a flag that indicates whether the event is part of an ongoing composition session. + // Safari does not support `isComposing` with the Japanese IME event, + // so we have to additionally check for the keyCode to handle that edge case. + !(e.nativeEvent.isComposing || e.keyCode === 229)) { e.preventDefault(); if (canSendMessage && input.trim().length !== 0) { sendMessage();