Skip to content

Commit 4f0cd01

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Libraries/LibWeb/HTML/HTMLInputElement.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,22 @@ void HTMLInputElement::clear_algorithm()
16481648
update_shadow_tree();
16491649
}
16501650

1651+
void HTMLInputElement::post_connection()
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+
}
1665+
}
1666+
16511667
void HTMLInputElement::form_associated_element_was_inserted()
16521668
{
16531669
create_shadow_tree_if_needed();

Libraries/LibWeb/HTML/HTMLInputElement.h

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class HTMLInputElement final
181181
virtual void reset_algorithm() override;
182182
virtual void clear_algorithm() override;
183183

184+
virtual void post_connection() override;
184185
virtual void form_associated_element_was_inserted() override;
185186
virtual void form_associated_element_was_removed(DOM::Node*) override;
186187
virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&, Optional<FlyString> const&) override;

0 commit comments

Comments
 (0)