commit cc67c80b2a4435348b4ce091845697cab9741334
parent e21bc5fe7644a6fe739ec716da92e48470e950d2
Author: Tomtron623 <60526206+Tomtron623@users.noreply.github.com>
Date: Fri, 24 Oct 2025 01:25:54 +0000
Bug 1658511 - added eConsumeNoDefault to fix double submission bug on enter and added/tested tests r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D266554
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp
@@ -3906,6 +3906,7 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
}
if (aVisitor.mPresContext) {
+ aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
MaybeSubmitForm(aVisitor.mPresContext);
}
}
diff --git a/testing/web-platform/tests/html/semantics/forms/the-input-element/keypress-link-trigger.tentative.html b/testing/web-platform/tests/html/semantics/forms/the-input-element/keypress-link-trigger.tentative.html
@@ -0,0 +1,48 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Do not trigger parent link when typing `Enter` in a single line text control</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-actions.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+"use strict";
+
+addEventListener("load", () => {
+ promise_test(async () => {
+ const form = document.querySelector("form");
+ let submitted = false;
+ form.addEventListener("submit", event => {
+ submitted = true;
+ event.preventDefault();
+ });
+ const textControl = document.querySelector("input[type=text]");
+ textControl.focus();
+ // typing `Enter` to submit the form
+ await new test_driver.Actions()
+ .keyDown("\uE007")
+ .keyUp("\uE007")
+ .send();
+ assert_true(submitted, "Typing `Enter` should've caused submitting the form");
+ assert_equals(
+ document.querySelector("span:target"),
+ null,
+ "The parent link should not be performed by typing `Enter` to submit the form"
+ );
+ });
+}, {once: true});
+</script>
+</head>
+<body>
+ <form action="#submit">
+ <a href="#anchor">
+ <input type="text">
+ <input type="submit">
+ </a>
+ </form>
+ <span id="anchor">targeted if the link is performed</span>
+</body>
+</html>