LibWeb: Don't double-dispatch click events on a label's child input

If the user clicked directly on the input inside a label, then it
already received a click event. Dispatching a second one via the label
is redundant, and means that if the input is a checkbox, it gets its
value toggled twice.
This commit is contained in:
Sam Atkins 2025-04-15 12:01:07 +01:00 committed by Tim Ledbetter
parent 81d4ed27d8
commit c00c0846c0
Notes: github-actions[bot] 2025-04-15 11:35:28 +00:00
3 changed files with 54 additions and 1 deletions

View file

@ -555,7 +555,7 @@ EventResult EventHandler::handle_mouseup(CSSPixelPoint viewport_position, CSSPix
}
if (auto* input_control = input_control_associated_with_ancestor_label_element(*paintable)) {
if (button == UIEvents::MouseButton::Primary) {
if (button == UIEvents::MouseButton::Primary && input_control != node) {
input_control->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, screen_position, page_offset, viewport_position, offset, {}, button, buttons, modifiers).release_value_but_fixme_should_propagate_errors());
}
}