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.

(cherry picked from commit 3856dd946b94b61be2ddac80c8cf60278fcc56ab;
amended to add two spaces to expected output due to serenity not yet
having LadybirdBrowser/ladybird#1603, and to add a trailing newline
to the test input file)
  • Loading branch information
Psychpsyo authored and nico committed Nov 18, 2024
1 parent 8da2929 commit c915179
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

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>
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,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

0 comments on commit c915179

Please sign in to comment.