Skip to content

fix(Button): default htmlType to button to prevent accidental form submission#1141

Open
munzzyy wants to merge 2 commits into
ClickHouse:mainfrom
munzzyy:fix/button-htmltype-default
Open

fix(Button): default htmlType to button to prevent accidental form submission#1141
munzzyy wants to merge 2 commits into
ClickHouse:mainfrom
munzzyy:fix/button-htmltype-default

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 5, 2026

Copy link
Copy Markdown

Why?

A native <button> without an explicit type defaults to type="submit". Button, IconButton, and SplitButton all accept an htmlType prop, but it was never defaulted, so it stayed undefined and the browser fell back to submit. Any of these rendered inside a <form> submits that form on click unless a caller remembers to pass htmlType="button". #1126 added the htmlType escape hatch and fixed a bunch of internal button usages, but left this specific default gap open, and the current test suite documents it directly (Button.test.tsx / IconButton.test.tsx both had a test literally titled "should not default to any type... thus behaving as type=submit").

Closes #1092.

How?

  • Defaulted htmlType = 'button' in the destructured props of Button, IconButton, and SplitButton.
  • Updated the existing "HTML types" test blocks in Button/IconButton: the old test asserted the buggy submit-by-default behavior, now it asserts the button does not submit by default and that type="button" is on the element. Added matching coverage to SplitButton.test.tsx, which had no test for the default case at all.
  • Added a new test to each component confirming htmlType="submit" still submits the form when set explicitly.
  • Checked every internal caller that relies on non-submit buttons (FileTabs, Select's InternalSelect, Table) — they already pass htmlType="button" explicitly, so this default doesn't change their behavior.
  • Bumped the changeset from patch to minor per @ariser's review: this changes runtime behavior for any consumer who was relying on the old default-submit fallback, so it's not safe to treat as a patch. Called it out explicitly in the changeset body.

Tickets?

Contribution checklist?

  • You've done enough research before writing
  • You have reviewed the PR
  • The commit messages are detailed
  • The build command runs locally
  • Assets or static content are linked and stored in the project
  • For documentation, guides or references, you've tested the commands

Security checklist?

  • All user inputs are validated and sanitized
  • No usage of dangerouslySetInnerHTML
  • Sensitive data has been identified and is being protected properly
  • Build output contains no secrets or API keys

Preview?

N/A — behavior-only change (default prop value), no visual change. yarn test (full suite, 505 tests) and yarn typecheck both pass locally.

Button and IconButton both accept an htmlType prop but never defaulted
it, so the native button fell back to the browser default of
type=submit. Any Button or IconButton inside a form submitted that
form on click unless htmlType was set explicitly.

Default htmlType to 'button' on both components. Consumers who want
submit behavior still opt in with htmlType="submit".

Closes ClickHouse#1092
@changeset-bot

changeset-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8fade1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ariser ariser Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  1. SplitButton has this prop as well https://github.com/ClickHouse/click-ui/blob/main/src/components/SplitButton/SplitButton.types.ts#L38
  2. This is a breaking change, we should not just merge it without a migration plan for consumers. We can't assume all use cases that expect default submit behavior are covered by tests. This can break silently.

@@ -0,0 +1,5 @@
---
'@clickhouse/click-ui': patch

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

definitely not a patch

Extends the Button/IconButton fix to SplitButton, which has the same
submit-by-default gap. Bumped the changeset from patch to minor since
defaulting htmlType is a behavior change for any consumer relying on
the old default-submit fallback.
@munzzyy

munzzyy commented Jul 6, 2026

Copy link
Copy Markdown
Author

Good catches, both fixed:

  1. Added the same default to SplitButton and covered it with tests (default-is-button, explicit button, explicit submit) — it had no coverage for the default case at all before this.
  2. Bumped the changeset to minor and called out plainly that this changes runtime behavior for anyone relying on the old default-submit fallback, with the workaround (htmlType="submit") spelled out.

Full suite (505 tests) and typecheck both pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Button and IconButton default to native type=submit, causing accidental form submissions

2 participants