Skip to content

Commit

Permalink
LibWeb: Prevent checkboxes from firing change events when losing focus
Browse files Browse the repository at this point in the history
This is because toggling the checkbox is committing the value.
  • Loading branch information
Psychpsyo authored and awesomekling committed Nov 18, 2024
1 parent c898ee9 commit 3856dd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions Libraries/LibWeb/HTML/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 3856dd9

Please sign in to comment.