-
Notifications
You must be signed in to change notification settings - Fork 599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button component has no default type #2806
Comments
👍 I completely agree - setting the default type to <form onSubmit={submitHandler}>
{/* ... */}
<Button onClick={cancelHandler}>Cancel</Button>
<Button type="submit" variant="primary">Primary</Button>
</form> Pressing "Cancel" in this form will unintentionally submit the form because the button doesn't have In fact this is so unexpected that we've considered using a linting rule to force all buttons in Memex to have explicit |
Opened up a quick PR here: #2807 to put it on |
I'd vote for adding it to |
Description
The
Button
component does not have a defaulttype
attribute. In e.g. react-bootstrap, theButton
component by default hastype
set tobutton
. Without such a default, thetype
will default tosubmit
within forms, yielding the following warning when using e.g. Formik:You submitted a Formik form using a button with an unspecified
type
attribute. Most browsers default button elements totype="submit"
. If this is not a submit button, please addtype="button"
.As it is normal to add multiple buttons within a form, it seems safer and more intuitive to have a default type set to
button
, and then explicitly specify which button to use for submission.Steps to reproduce
type=submit
instead oftype=button
. Expected behavior would be that the secondButton
type would default tobutton
.Version
v35.2.0
Browser
Firefox
The text was updated successfully, but these errors were encountered: