-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
add type="button" to all components using button element #150
add type="button" to all components using button element #150
Conversation
🦋 Changeset detectedLatest commit: 8efa3b1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
3a9091b
to
a30b785
Compare
Hey @wysher , thanks for this! I don't think it should be able to be changed at all tbh. If someone really wants to change it, they can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing this! We could also probably Omit
the type
prop from the TriggerProps
as well!
@@ -7,6 +7,7 @@ | |||
type $$Props = TriggerProps; | |||
type $$Events = TriggerEvents; | |||
export let asChild = false; | |||
export let type: $$Props["type"] = "button"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export let type: $$Props["type"] = "button"; |
@@ -22,6 +23,7 @@ | |||
use:melt={builder} | |||
{...$$restProps} | |||
{...attrs} | |||
{type} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{type} | |
type="button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huntabyte all done. And also more... I searched for button elements within bits components and added more type=button
. I'm pretty sure all of them needs it.
Especially checkbox or radio - you don't want form inputs to trigger submit at any time. Same with tabs, popovers, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're incredible, thank you!
a30b785
to
e0f77b1
Compare
e0f77b1
to
10b8b52
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the rest of the buttons, I think we should do something like this:
type="button"
{...$$restProps}
{...attrs}
That way, if for some reason or another someone wants to submit the form when they close the dialog, or toggle a switch, or whatever, they are able to override the type="button"
we set by passing type="submit"
since the ...$$restProps
follows our hardcoded type.
@@ -23,6 +23,7 @@ | |||
use:melt={builder} | |||
{...$$restProps} | |||
{...attrs} | |||
type="button" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type="button" |
I think we leave this up to the dev to add here if they wish. Imagine you wanted to add a tooltip to a button that submits a form, with the tooltip saying "Submit form" or something. We don't want to prevent the user from doing something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense here. Done.
src/lib/bits/tooltip/types.ts
Outdated
@@ -30,7 +30,7 @@ type ContentProps< | |||
> & | |||
HTMLDivAttributes; | |||
|
|||
type TriggerProps = AsChild & HTMLButtonAttributes; | |||
type TriggerProps = AsChild & Omit<HTMLButtonAttributes, "type">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type TriggerProps = AsChild & Omit<HTMLButtonAttributes, "type">; | |
type TriggerProps = AsChild & HTMLButtonAttributes; |
10b8b52
to
8792ea3
Compare
8792ea3
to
3da300f
Compare
3da300f
to
8659f1f
Compare
8659f1f
to
1286729
Compare
1286729
to
18be0ca
Compare
18be0ca
to
9da5e6b
Compare
9da5e6b
to
8efa3b1
Compare
Thanks again @wysher! |
One and only reason is that changed components here uses button
element under the hood - without developer knowledge.
Button component which will be deliberately used by developer was not
changed by this PR.
pon., 6 lis 2023 o 19:17 Wilson Hobbs ***@***.***> napisał(a):
… What's the reasoning here? Default HTML behavior is no type attribute,
and if it is within a form, the expectation is that the developer will add
type="button" to prevent submit. Is there a good reason to go against the
web standard?
—
Reply to this email directly, view it on GitHub
<#150 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEA7U5HDJKWIL7WI5AP2VRTYDEZUNAVCNFSM6AAAAAA6UJX7EGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJWGA4DOOBSGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@huntabyte this one left me with one question. Maybe AlertDialogAction should not set type="button" as default, cause it looks like submit and AlertDialogContent may be wrapped with form? |
I realized and deleted my comments after. Great PR! :) |
Using SelectTrigger shadcn/svelte with forms causes form submit. This happens, because button by default has
type="submit"
.I think it's good idea to set
type="button"
instead, to prevent unwanted submits.Here's implementation which allows to change it by developer, but maybe it should not be possible to changed at all?