Bug 239964

Summary: The select element does not fire click events
Product: WebKit Reporter: Daniel Jacobs <danielhunterjacobs>
Component: UI EventsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: akeerthi, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugzilla.mozilla.org/show_bug.cgi?id=1767062
https://bugs.webkit.org/show_bug.cgi?id=240135
Attachments:
Description Flags
Safari behavior tested
none
Test case none

Description Daniel Jacobs 2022-05-02 08:19:12 PDT
Created attachment 458681 [details]
Safari behavior tested

Create this page and see that the click event is not triggered when using normal nor accessible ways of choosing options:

<!DOCTYPE html>
<html>
<body>
<h1>Onclick select test</h1>
<label for="select">Select an option:</label>
<select id="select">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<div>Total number of onclick events: <span id="output">0</span></div>
<script>
const select = document.getElementById("select");
const output = document.getElementById("output");
select.addEventListener("click", function() {
output.textContent = parseInt(output.textContent) + 1;
});
</script>
</body>
</html>

What Chromium browsers do is trigger the click event for select elements whenever an option is selected. This includes triggering the event when selection is made using the keyboard. When to fire it is arguable: you could argue it should fire both when opening the select and selecting an option, though I feel that's less useful and that doesn't match Chromium behavior. However, it should not never fire, and it currently doesn't in Safari.

cc: https://bugzilla.mozilla.org/show_bug.cgi?id=1767062
Comment 1 Daniel Jacobs 2022-05-02 08:26:36 PDT
Created attachment 458682 [details]
Test case
Comment 2 Radar WebKit Bug Importer 2022-05-09 08:20:32 PDT
<rdar://problem/92962113>
Comment 3 Daniel Jacobs 2022-05-09 08:44:38 PDT
Opened https://github.com/whatwg/html/issues/7907