-
Notifications
You must be signed in to change notification settings - Fork 904
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
Buttons don't respect preventDefault in forms and try to force submit #5032
Buttons don't respect preventDefault in forms and try to force submit #5032
Comments
Issue Workaround If using https://lit.dev/playground/#gist=77bf6a3dcca4b1ae302d380db9aacfb9 |
It looks like this issue may come up elsewhere and needs a holistic fix. All the See this example showing microtasks interacting with bubbling listeners. |
Yes! We have an overall tracking bug for ensuring If you find additional spots where |
… default Fixes #5032 PiperOrigin-RevId: 588890283
… default Fixes #5032 PiperOrigin-RevId: 588890283
What is affected?
Component
Description
Whenever I click on an MWC button inside a form, the validity checks start going off. Usually this happens because buttons inside a form trigger the submit behavior, which can be stopped by calling
preventDefault
on the event.Attaching a
click
listener to a MWC button to prevent the submission doesn't do anything. On a native<button>
however the validity check and submission is stoppedReproduction
You can see an example here, with an icon button, a filled one and a native button. Just start clicking the buttons without filling any of the inputs to notice the jarring effect.
https://lit.dev/playground/#gist=2245bd0b6209c8d3519ff1505c15bd86
The native one works as expected, respecting the
preventDefault
, the mwc ones keep on trying to submit the form.Workaround
No workaround.
Setting
type="button"
would stop the form submission completely instead of preventing the default behavior as expected.Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
1.0.0
Browser/OS/Node environment
Browser: Chrome 117.0.5938.92
OS: Windows 11 Pro 22H2 22621.2283
Node: v18.16.0
npm: 9.6.7
The text was updated successfully, but these errors were encountered: