From c915179332362043b4d195b82a19b5fa875c5e4b Mon Sep 17 00:00:00 2001 From: Psychpsyo Date: Sat, 16 Nov 2024 12:33:40 +0100 Subject: [PATCH] LibWeb: Prevent checkboxes from firing change events when losing focus 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) --- .../checkbox-focus-lost-no-change-event.txt | 1 + .../checkbox-focus-lost-no-change-event.html | 16 ++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLInputElement.cpp | 1 + 3 files changed, 18 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/checkbox-focus-lost-no-change-event.txt create mode 100644 Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html diff --git a/Tests/LibWeb/Text/expected/checkbox-focus-lost-no-change-event.txt b/Tests/LibWeb/Text/expected/checkbox-focus-lost-no-change-event.txt new file mode 100644 index 00000000000000..1a4baf536d705b --- /dev/null +++ b/Tests/LibWeb/Text/expected/checkbox-focus-lost-no-change-event.txt @@ -0,0 +1 @@ + diff --git a/Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html b/Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html new file mode 100644 index 00000000000000..0a581b3100b7a4 --- /dev/null +++ b/Tests/LibWeb/Text/input/checkbox-focus-lost-no-change-event.html @@ -0,0 +1,16 @@ + + + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index b56feaa12cc6b0..7f7ad756fd92c4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -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;