From 8169b878f839a2745ffd938945065ef7f30b1291 Mon Sep 17 00:00:00 2001 From: Mathis Wiehl Date: Sat, 18 Mar 2023 15:45:54 +0100 Subject: [PATCH] LibWeb: Invalidate sibling styles on input element checked state change Checkedness of an input element can influence sibling style, as well as style of their children, when they use the `:checked` pseudo-class in combination with a kind of sibling selector. That means its not sufficient to just invalidate the input elements on style. This is actually more commonly observable than one might expect, because this pattern is often used as a JS-free toggle solution for things like menus. --- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 3b49810840..3b2ba90978 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -85,7 +85,12 @@ void HTMLInputElement::set_checked(bool checked, ChangeSource change_source) m_dirty_checkedness = true; m_checked = checked; - set_needs_style_update(true); + + // This element's :checked pseudo-class could be used in a sibling's sibling-selector, + // so we need to invalidate the style of all siblings. + parent()->for_each_child([&](auto& child) { + child.invalidate_style(); + }); } void HTMLInputElement::set_checked_binding(bool checked)