Skip to content
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

RFC: button.type should default to button, not submit? #178

Open
raquo opened this issue Nov 11, 2024 · 1 comment
Open

RFC: button.type should default to button, not submit? #178

raquo opened this issue Nov 11, 2024 · 1 comment

Comments

@raquo
Copy link
Owner

raquo commented Nov 11, 2024

HTML spec says that a <button> element without an explicitly specified type attribute should be interpreted to have type=submit.

This makes some amount of sense for applications that consist of HTML forms that are submitted with such buttons, but Laminar is primarily designed for SPA applications, where most buttons do not submit any html forms.

Forgetting to specify type=button leads to buttons that do the wrong thing – submit the html form they're in – instead of performing the onClick or other action that we expect of them. And the way we're building our apps, the helper function in which the button is defined may not know whether it will be rendered in a form or not, so if type=button is not specified, it may work initially if rendered outside of the form, but fail when the button is moved to inside a form.

Correctly specifying type=button results in a bit of extra boilerplate for the majority use case.


High-level web component libraries such as Shoelace generally default to type=button in their button components. Lower level libraries like React.js generally stick to the native HTML behaviour, i.e. have type=submit as a default.

I'm wondering if Laminar should also default to type=button, even if it's decidedly a low level library. The type=submit default just seems to be so counter-productive. I'm well aware of this default, and yet I still often forget to specify type=button.

For me personally, building SPAs, type=submit is a rare use case, so I always specify it explicitly. I don't make use of the default in the spec, and personally would be happy to not need to type out type=button on 90% of the buttons I create.

Yet at the same time, adding a special type=button default to Laminar could confuse people. While the various HTML docs and tutorials including MDN generally specify type=submit attribute explicitly when it's intended to submit a form, if you do follow some tutorial that omits type=submit and relies on it being the default, you would need to look at Laminar docs to find why your form is not submitting, which goes against Laminar's general advice that you should look at html docs because Laminar behaves the way html behaves.

Normally we could hope for the standard / spec to improve eventually, but this is HTML – it will never change such a fundamental default, no matter how broken it is.


I haven't yet decided one way or another, except that whatever we choose, will be the only default available in Laminar, with no conditions and no configuration.

I would like to hear your opinion – regardless of whether you're experienced in Laminar / frontend / DOM / HTML or not.

  • Would having type=button as default improve Laminar ergonomics for you?
  • Do you often use button without specifying its type, relying on the default?
  • How surprised and frustrated would you be to encounter this non-standard default in Laminar, if you didn't know it was there?
@j-mie6
Copy link

j-mie6 commented Nov 11, 2024

Personally, I've only used buttons with the type set to button; I'm in favour of this proposal.

Perhaps this could be mitigated with a separate button method, something like formButton or submit or formSubmit for instance to serve as a button with the "classic" HTML default?

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

No branches or pull requests

2 participants