-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Default Switch
to type="button"
#178
Comments
I'd be happy to supply a PR if you're onboard. |
Closes: #178 Co-authored-by: =?UTF-8?q?Oskar=20L=C3=B6fgren?= <[email protected]>
Hey! Thank you for your suggestion! I implemented it myself here #192 however I marked you as a co-author! |
This issue also seems to occur if the If the |
Problem
Ran into an interesting behavior where hitting Enter on/in another form field toggled the switch state. To be clear: the switch was not focused.
Demo
Cause
After some digging, I found the reason to be: a
<button>
inside a<form>
is implicitly assignedtype="submit"
if nothing else is specified. Hitting Enter inside a<form>
triggers a click on the first submit (implicit or not) button in the form. Since, in my case, the<Switch>
is the first such button of the form and there's anonClick
handler assigned, the<Switch>
is toggled.Workaround
Explicitly set
<Switch type="button">
.Solution
When
<Switch>
is rendered as<button>
(as per default), explicitly settype="button"
by default.Rationale
I can't think of a valid reason the current behavior is ever desired.
The text was updated successfully, but these errors were encountered: