Skip to content

Commit ab6830b

Browse files
committed
LibWeb/HTML: Update radio group when a checked radio button is inserted
Corresponds to whatwg/html#10917
1 parent 7da3b06 commit ab6830b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Libraries/LibWeb/HTML/HTMLInputElement.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,19 @@ void HTMLInputElement::clear_algorithm()
16491649
void HTMLInputElement::form_associated_element_was_inserted()
16501650
{
16511651
create_shadow_tree_if_needed();
1652+
1653+
// https://html.spec.whatwg.org/multipage/input.html#radio-button-state-(type=radio)
1654+
// When any of the following phenomena occur, if the element's checkedness state is true after the occurrence,
1655+
// the checkedness state of all the other elements in the same radio button group must be set to false:
1656+
// ...
1657+
// - The element becomes connected.
1658+
if (type_state() == TypeAttributeState::RadioButton && checked()) {
1659+
root().for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& element) {
1660+
if (element.checked() && &element != this && is_in_same_radio_button_group(*this, element))
1661+
element.set_checked(false);
1662+
return TraversalDecision::Continue;
1663+
});
1664+
}
16521665
}
16531666

16541667
void HTMLInputElement::form_associated_element_was_removed(DOM::Node*)

0 commit comments

Comments
 (0)