LibWeb/HTML: Signal a type change

Type changes are now signaled to radio buttons. This causes other radio
buttons in the group to be unchecked if the input element is a checked
radio button after the type change.
This commit is contained in:
Glenn Skrzypczak 2025-04-20 19:48:47 +02:00 committed by Tim Ledbetter
parent 5f75558646
commit d4076ec9fa
Notes: github-actions[bot] 2025-04-23 06:21:06 +00:00
4 changed files with 44 additions and 1 deletions

View file

@ -1456,7 +1456,8 @@ void HTMLInputElement::type_attribute_changed(TypeAttributeState old_state, Type
set_shadow_root(nullptr);
create_shadow_tree_if_needed();
// FIXME: 5. Signal a type change for the element. (The Radio Button state uses this, in particular.)
// 5. Signal a type change for the element. (The Radio Button state uses this, in particular.)
signal_a_type_change();
// 6. Invoke the value sanitization algorithm, if one is defined for the type attribute's new state.
m_value = value_sanitization_algorithm(m_value);
@ -1475,6 +1476,23 @@ void HTMLInputElement::type_attribute_changed(TypeAttributeState old_state, Type
}
}
// https://html.spec.whatwg.org/multipage/input.html#radio-button-state-(type=radio):signal-a-type-change
void HTMLInputElement::signal_a_type_change()
{
// https://html.spec.whatwg.org/multipage/input.html#radio-button-state-(type=radio)
// When any of the following phenomena occur, if the element's checkedness state is true after the occurrence,
// the checkedness state of all the other elements in the same radio button group must be set to false:
// ...
// - A type change is signalled for the element.
if (type_state() == TypeAttributeState::RadioButton && checked()) {
root().for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& element) {
if (element.checked() && &element != this && is_in_same_radio_button_group(*this, element))
element.set_checked(false);
return TraversalDecision::Continue;
});
}
}
// https://html.spec.whatwg.org/multipage/input.html#attr-input-src
WebIDL::ExceptionOr<void> HTMLInputElement::handle_src_attribute(String const& value)
{