Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/copilot): don't send on Enter on touch devices (#15082)

AutoGPT44be5cea6883
diff --git a/autogpt_platform/frontend/src/components/ai-elements/__tests__/prompt-input.test.tsx b/autogpt_platform/frontend/src/components/ai-elements/__tests__/prompt-input.test.tsx
index 735cf4054d..9c803cf571 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/__tests__/prompt-input.test.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/__tests__/prompt-input.test.tsx
@@ -65,6 +65,20 @@ describe("PromptInputTextarea Enter handling", () => {
expect(onSubmit).not.toHaveBeenCalled();
});
+ it("does not submit on Enter on touch devices", () => {
+ window.matchMedia = vi.fn().mockReturnValue({ matches: true });
+ try {
+ const { textarea, onSubmit } = renderComposer();
+
+ fireEvent.keyDown(textarea, { key: "Enter" });
+
+ expect(onSubmit).not.toHaveBeenCalled();
+ } finally {
+ // @ts-expect-error jsdom has no matchMedia by default
+ delete window.matchMedia;
+ }
+ });
+
it("lets a consumer onKeyDown claim the key first", () => {
const onSubmit = vi.fn();
render(
diff --git a/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx b/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
index ebab05b6f0..5545001efd 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
@@ -251,6 +251,9 @@ export function PromptInputTextarea({
if (isKey(e, "Enter")) {
if (e.shiftKey) return;
+ // On touch-first devices (phones/tablets) Enter inserts a newline;
+ // users send with the submit button instead.
+ if (window.matchMedia?.("(pointer: coarse)")?.matches) return;
e.preventDefault();
e.currentTarget.form?.requestSubmit();