-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Comments
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 |
I believe it's best to follow the spec, otherwise what are we basing it on really. Maybe add another shorthand for button which is type=button Are there ANY other applications where it would also make sense to deviate from HTML standard? |
@krestenlaust This is, indeed, in essence, a question of naming, specifically – which version gets the "good" For example, we could alias Or, the other way – keep Laminar names normally differ a bit from the underlying DOM names as described here, mostly to match Scala style, to avoid using a common variable name, and to avoid name conflicts, for example:
In other low-level HTML libs, OTOH: React.js famously made its React did this because back then, the Of course, all these situations are unique, different from the current case in one way or another. For example, the React team should have had the expectation that the relevant browsers will eventually support |
We could also use For some precedent – we already do this naming pattern with Of course, |
Btw here's another example of how following HTML spec can produce undesired results: #180 – that issue keeps tripping people, so we will eventually need a better way to set the |
HTML spec says that a
<button>
element without an explicitly specifiedtype
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.
type=button
as default improve Laminar ergonomics for you?button
without specifying itstype
, relying on the default?The text was updated successfully, but these errors were encountered: