Skip to content

Commit

Permalink
Patch input to handle Enter event for japanese keyboards correctly (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbramblett authored May 16, 2024
1 parent 9dd7b00 commit 70051e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"main": "./lib/commonjs/src/index.js",
Expand Down
7 changes: 6 additions & 1 deletion src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ export function ChatInput({

const handleKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
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();
Expand Down

0 comments on commit 70051e5

Please sign in to comment.