Skip to content

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

Description

@danny-avila

Summary

A native <button> without an explicit type defaults to type="submit". Because Button and IconButton never set the native type, every click-ui button rendered inside a <form> becomes a submit button. Clicking an unrelated button (an "add item" button, a delete/trash icon, etc.) submits the surrounding form.

The type prop is reused for the visual variant, so there is no obvious way to set the native type.

Current state (v0.6.1)

  • Button has an htmlType prop, but it is not defaulted, so it still inherits the browser default of submit.
  • IconButton has no htmlType prop at all, so there is no way to make it a non-submit button via the public API.

Repro

<form onSubmit={() => console.log('submitted')}>
  <IconButton icon="trash" onClick={removeRow} />
  <Button type="secondary" label="Add item" onClick={addRow} />
  <Button type="primary" label="Save" htmlType="submit" />
</form>

Clicking "Add item" or the trash icon submits the form.

Proposed fix

  1. Add an htmlType prop to IconButton for parity with Button.
  2. Default htmlType to "button" on both Button and IconButton, and forward it to the native element's type. Consumers opt in to submit with htmlType="submit".

This matches the convention used by Ant Design, MUI, and Chakra, and removes the accidental-submit footgun.

const Button = ({ type = 'primary', htmlType = 'button', ...delegated }) =>
  <StyledButton $styleType={type} type={htmlType} {...delegated} />;

Breaking change note

Defaulting to "button" means consumers relying on implicit submit must add htmlType="submit" to their submit buttons. This is a deliberate, greppable change and safer than the current silent-submit default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions