Skip to content

Commit de24fa6

Browse files
committed
LibWeb/HTML: Update radio group when a checked radio button is connected
Corresponds to whatwg/html#10917
1 parent a01a3b1 commit de24fa6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Libraries/LibWeb/HTML/HTMLInputElement.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,21 @@ void HTMLInputElement::clear_algorithm()
16801680
void HTMLInputElement::form_associated_element_was_inserted()
16811681
{
16821682
create_shadow_tree_if_needed();
1683+
1684+
if (is_connected()) {
1685+
// https://html.spec.whatwg.org/multipage/input.html#radio-button-state-(type=radio)
1686+
// When any of the following phenomena occur, if the element's checkedness state is true after the occurrence,
1687+
// the checkedness state of all the other elements in the same radio button group must be set to false:
1688+
// ...
1689+
// - The element becomes connected.
1690+
if (type_state() == TypeAttributeState::RadioButton && checked()) {
1691+
root().for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& element) {
1692+
if (element.checked() && &element != this && is_in_same_radio_button_group(*this, element))
1693+
element.set_checked(false);
1694+
return TraversalDecision::Continue;
1695+
});
1696+
}
1697+
}
16831698
}
16841699

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

0 commit comments

Comments
 (0)