Skip to content

Commit

Permalink
fix(frontend): Prevent message submission during IME composition (#6025)
Browse files Browse the repository at this point in the history
  • Loading branch information
siu-issiki authored Jan 4, 2025
1 parent 33cb1d5 commit e6499a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions frontend/__tests__/components/chat/chat-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,30 @@ describe("ChatInput", () => {
// Verify image paste was handled
expect(onImagePaste).toHaveBeenCalledWith([file]);
});

it("should not submit when Enter is pressed during IME composition", async () => {
const user = userEvent.setup();
render(<ChatInput onSubmit={onSubmitMock} />);
const textarea = screen.getByRole("textbox");

await user.type(textarea, "こんにちは");

// Simulate Enter during IME composition
fireEvent.keyDown(textarea, {
key: "Enter",
isComposing: true,
nativeEvent: { isComposing: true },
});

expect(onSubmitMock).not.toHaveBeenCalled();

// Simulate normal Enter after composition is done
fireEvent.keyDown(textarea, {
key: "Enter",
isComposing: false,
nativeEvent: { isComposing: false },
});

expect(onSubmitMock).toHaveBeenCalledWith("こんにちは");
});
});
7 changes: 6 additions & 1 deletion frontend/src/components/features/chat/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export function ChatInput({
};

const handleKeyPress = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (event.key === "Enter" && !event.shiftKey && !disabled) {
if (
event.key === "Enter" &&
!event.shiftKey &&
!disabled &&
!event.nativeEvent.isComposing
) {
event.preventDefault();
handleSubmitMessage();
}
Expand Down

0 comments on commit e6499a6

Please sign in to comment.