Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): Prevent message submission during IME composition (#6025)

siue6499a68f62a
diff --git a/frontend/__tests__/components/chat/chat-input.test.tsx b/frontend/__tests__/components/chat/chat-input.test.tsx
index 7947b67d41..3cf83a1e7b 100644
--- a/frontend/__tests__/components/chat/chat-input.test.tsx
+++ b/frontend/__tests__/components/chat/chat-input.test.tsx
@@ -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("こんにけは");
+ });
});
diff --git a/frontend/src/components/features/chat/chat-input.tsx b/frontend/src/components/features/chat/chat-input.tsx
index 43011aafdf..02e346ca27 100644
--- a/frontend/src/components/features/chat/chat-input.tsx
+++ b/frontend/src/components/features/chat/chat-input.tsx
@@ -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();
}