LibWeb: Check all elements in same tree to determine labeled control

Previously, when looking for the labeled control of a label element, we
were only checking its child elements. The specification says we should
check all elements in the same tree as the label element.
This commit is contained in:
Tim Ledbetter 2024-05-17 06:05:39 +01:00 committed by Andreas Kling
parent fc395716e9
commit 5296338e7a

View file

@ -43,7 +43,7 @@ JS::GCPtr<HTMLElement> HTMLLabelElement::control() const
// and the first such element in tree order is a labelable element, then that element is the
// label element's labeled control.
if (for_().has_value()) {
for_each_in_inclusive_subtree_of_type<HTMLElement>([&](auto& element) {
root().for_each_in_inclusive_subtree_of_type<HTMLElement>([&](auto& element) {
if (element.id() == *for_() && element.is_labelable()) {
control = &const_cast<HTMLElement&>(element);
return TraversalDecision::Break;