Skip to content

fix: prevent attachment button click from triggering form submit#1471

Open
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/web-attachment-button-submit
Open

fix: prevent attachment button click from triggering form submit#1471
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/web-attachment-button-submit

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 17, 2026

Problem

Clicking the attachment (paperclip) button in the web UI triggers a form submit, sending the current input text before the file dialog opens.

Fix

Add event.preventDefault() and event.stopPropagation() to the attachment button's click handler to ensure only the file dialog is opened.

Fixes #1428


Open with Devin

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@Br1an67 Br1an67 force-pushed the fix/web-attachment-button-submit branch from d9f04d2 to 363f806 Compare March 17, 2026 07:19
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 363f806b01

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +9 to +12
onClick={(e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
attachments.openFileDialog();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply submit guard on the rendered attachment trigger

This handler is added to AttachmentButton, but that component is not imported anywhere in web/src (repo-wide rg "AttachmentButton" only finds this definition), so the fix never runs in the chat composer. The attachment control users actually click is in global-config-controls.tsx (<Button onClick={() => attachments.openFileDialog()}> inside PromptInput), so the reported submit-on-click behavior remains unchanged after this commit.

Useful? React with 👍 / 👎.

The Paperclip (attach files) button in GlobalConfigControls is rendered
inside the prompt form without an explicit type attribute. Since the
default button type in a form is 'submit', clicking it triggers a form
submission in addition to opening the file dialog.

Add type="button" to prevent the implicit form submit.

Fixes MoonshotAI#1428
@Br1an67 Br1an67 force-pushed the fix/web-attachment-button-submit branch from 363f806 to 480fcca Compare March 17, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant