You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found the following code in script/dom/document_event_handler.rs:
// This behavior is unspecced// We are supposed to dispatch synthetic click activation for Space and/or Return,// however *when* we do it is up to us.// Here, we're dispatching it after the key event so the script has a chance to cancel it// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337if(keyboard_event.event.key == Key::Named(NamedKey::Enter) ||
keyboard_event.event.code == Code::Space) &&
keyboard_event.event.state == KeyState::Up{ifletSome(elem) = target.downcast::<Element>(){
elem.upcast::<Node>().fire_synthetic_pointer_event_not_trusted(DOMString::from("click"), can_gc);}}
Pressing enter or spacebar triggers the onclick event. Neither Firefox nor Chromium fire these events.
There are some old specifications that say that some elements should receive a click event for accessibility reasons on enter or space. I noticed in Firefox if you focus a link with the tab key and then press enter, then you get a click event. You don't get a click event with space or the up key though.
Is there a better specification that lists exactly which elements should generate a click event for which keys?
If the key is the Enter or (Space) key and the current focus is on a state-changing element, the default action MUST be to dispatch a click event, and a DOMActivate event if that event type is supported by the user agent.
Step 5 of that last link seems important. I think the intended spec logic here is:
First dispatch a keydown event
If the event is handled, do nothing
Otherwise, if the focus is on an element with an activation behaviour, and the key is space or enter, fire an untrusted MouseEvent named click at the element
Step 5 of that last link seems important. I think the intended spec logic here is:
* First dispatch a keydown event
* If the event is handled, do nothing
* Otherwise, if the focus is on an element with an activation behaviour, and the key is space or enter, fire an untrusted MouseEvent named click at the element
Great! That sounds reasonable. Thanks for digging that out! 😀
Activity
MichaelMcDonnell commentedon Aug 29, 2025
I found the following code in
script/dom/document_event_handler.rs:Pressing enter or spacebar triggers the onclick event. Neither Firefox nor Chromium fire these events.
[-]Spacebar in text input causes onclick event[/-][+]Spacebar in text input causes click event[/+]MichaelMcDonnell commentedon Aug 29, 2025
There are some old specifications that say that some elements should receive a click event for accessibility reasons on enter or space. I noticed in Firefox if you focus a link with the tab key and then press enter, then you get a click event. You don't get a click event with space or the up key though.
Is there a better specification that lists exactly which elements should generate a click event for which keys?
jdm commentedon Sep 5, 2025
I was assuming that the code you linked was attempting to implement https://html.spec.whatwg.org/#implicit-submission, although I don't see why we would be using an untrusted event in that case.
jdm commentedon Sep 5, 2025
It's also possible that it was poorly implementing the behaviour of pressing spacebar to press a focused button element.
jdm commentedon Oct 9, 2025
I think his has been somewhat specc'ed at https://w3c.github.io/uievents/#event-type-keydown . See:
Also:
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission
https://html.spec.whatwg.org/multipage/interaction.html#activation
https://html.spec.whatwg.org/multipage/interaction.html#focus-processing-model:fire-a-click-event
jdm commentedon Oct 9, 2025
Step 5 of that last link seems important. I think the intended spec logic here is:
MichaelMcDonnell commentedon Oct 10, 2025
Great! That sounds reasonable. Thanks for digging that out! 😀
script: Do not fire simulated click on spacebar/enter in non-state-ch…
MichaelMcDonnell commentedon Mar 25, 2026
Thank you for fixing this @mrobinson! It's great to see progress with the text issues 😀