Bug 239964 - The select element does not fire click events
Summary: The select element does not fire click events
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 15
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-05-02 08:19 PDT by Daniel Jacobs
Modified: 2022-05-09 08:44 PDT (History)
2 users (show)

See Also:


Attachments
Safari behavior tested (124.76 MB, video/quicktime)
2022-05-02 08:19 PDT, Daniel Jacobs
no flags Details
Test case (524 bytes, text/html)
2022-05-02 08:26 PDT, Daniel Jacobs
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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