From b1d0b6a37bed9512805cfab07da15cca8f750238 Mon Sep 17 00:00:00 2001 From: elomscansio <163124154+elomscansio@users.noreply.github.com> Date: Mon, 28 Apr 2025 02:24:43 +0100 Subject: [PATCH] htmlinputelement: Update radio group validity logic for disconnected trees (#36431) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR updates the validity state revalidation behavior for radio input elements, ensuring consistent logic regardless of tree connectivity. --- **What’s changed:** - we now always update the validity state. - Handled more edge cases for disconnected trees, shadow roots, and cross-tree movement. - Ensured that radio group updates still trigger when a parent is moved into a different root. - Updated test expectations in `radio-disconnected-group-owner.html.ini`. --- **Why this matters:** The updated logic aligns better with the [HTML specification](https://html.spec.whatwg.org/multipage/input.html#radio-button-group), especially regarding radio group behavior in disconnected trees or shadow DOM. These changes improve validity propagation in scenarios like: - Appending inputs into a disconnected form - Shadow roots acting as radio group containers - Cross-tree movement of radio buttons --- **Tests:** - Modified `radio-disconnected-group-owner.html.ini` - Removed a test that now passes - Added a failing test expectation caused by a spec bug: the fragment parsing algorithm uses the connected tree for HTML set via `innerHTML`, affecting radio group computation --- **Spec reference:** https://html.spec.whatwg.org/multipage/input.html#radio-button-group --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report an errors - [ ] These changes fix # - [X] There are tests for these changes Signed-off-by: Emmanuel Paul Elom --- components/script/dom/htmlinputelement.rs | 6 +++++- .../radio-disconnected-group-owner.html.ini | 5 +---- .../html/semantics/forms/the-input-element/radio.html.ini | 3 --- 3 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 tests/wpt/meta/html/semantics/forms/the-input-element/radio.html.ini diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 1999c7193ff..aff8168b8fe 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -1257,6 +1257,7 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-input-checked fn SetChecked(&self, checked: bool) { self.update_checked_state(checked, true); + update_related_validity_states(self, CanGc::note()) } // https://html.spec.whatwg.org/multipage/#dom-input-readonly @@ -1697,7 +1698,7 @@ fn radio_group_iter<'a>( ) -> impl Iterator> + 'a { root.traverse_preorder(ShadowIncluding::No) .filter_map(DomRoot::downcast::) - .filter(move |r| &**r == elem || in_same_group(r, form, group, None)) + .filter(move |r| &**r == elem || in_same_group(r, form, group, Some(root))) } fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>) { @@ -2580,6 +2581,9 @@ impl VirtualMethods for HTMLInputElement { self.upcast::() .check_ancestors_disabled_state_for_form_control(); + if self.input_type() == InputType::Radio { + self.radio_group_updated(self.radio_group_name().as_ref()); + } update_related_validity_states(self, can_gc); } diff --git a/tests/wpt/meta/html/semantics/forms/the-input-element/radio-disconnected-group-owner.html.ini b/tests/wpt/meta/html/semantics/forms/the-input-element/radio-disconnected-group-owner.html.ini index 7d856ecad7b..6dfadc234e7 100644 --- a/tests/wpt/meta/html/semantics/forms/the-input-element/radio-disconnected-group-owner.html.ini +++ b/tests/wpt/meta/html/semantics/forms/the-input-element/radio-disconnected-group-owner.html.ini @@ -1,6 +1,3 @@ [radio-disconnected-group-owner.html] - [Removed elements are moved into separate radio groups.] - expected: FAIL - - [Appending input radio input into a disconnect form should update the other radio inputs in the same radio group.] + [Appending input radio input into a disconnect tree don't update the other radio inputs in the same radio group.] expected: FAIL diff --git a/tests/wpt/meta/html/semantics/forms/the-input-element/radio.html.ini b/tests/wpt/meta/html/semantics/forms/the-input-element/radio.html.ini deleted file mode 100644 index e6320078ac5..00000000000 --- a/tests/wpt/meta/html/semantics/forms/the-input-element/radio.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[radio.html] - [Radio buttons in an orphan tree should make a group] - expected: FAIL