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
- Add an
htmlType prop to IconButton for parity with Button.
- 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.
Summary
A native
<button>without an explicittypedefaults totype="submit". BecauseButtonandIconButtonnever 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
typeprop is reused for the visual variant, so there is no obvious way to set the native type.Current state (v0.6.1)
Buttonhas anhtmlTypeprop, but it is not defaulted, so it still inherits the browser default ofsubmit.IconButtonhas nohtmlTypeprop at all, so there is no way to make it a non-submit button via the public API.Repro
Clicking "Add item" or the trash icon submits the form.
Proposed fix
htmlTypeprop toIconButtonfor parity withButton.htmlTypeto"button"on bothButtonandIconButton, and forward it to the native element'stype. Consumers opt in to submit withhtmlType="submit".This matches the convention used by Ant Design, MUI, and Chakra, and removes the accidental-submit footgun.
Breaking change note
Defaulting to
"button"means consumers relying on implicit submit must addhtmlType="submit"to their submit buttons. This is a deliberate, greppable change and safer than the current silent-submit default.