浏览代码

LibWeb: Prevent checkboxes from firing change events when losing focus

This is because toggling the checkbox is committing the value.
Psychpsyo 8 月之前
父节点
当前提交
3856dd946b

+ 1 - 0
Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -637,6 +637,7 @@ void HTMLInputElement::commit_pending_changes()
     case TypeAttributeState::Telephone:
     case TypeAttributeState::Text:
     case TypeAttributeState::URL:
+    case TypeAttributeState::Checkbox:
         if (!m_has_uncommitted_changes)
             return;
         break;

+ 0 - 0
Tests/LibWeb/Text/expected/checkbox-focus-lost-no-change-event.txt


+ 16 - 0
Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<input type="checkbox" id="checkbox">
+<script src="include.js"></script>
+<script>
+    checkbox.addEventListener("change", () => {
+      println("Change event was fired when it shouldn't have been.");
+    });
+    asyncTest(async done => {
+        checkbox.focus();
+        await new Promise(resolve => setTimeout(resolve, 0));
+        checkbox.blur();
+        await new Promise(resolve => setTimeout(resolve, 0));
+
+        done();
+    });
+</script>