Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire keypress event for Enter, Shift+Enter, and Ctrl+Enter keys #392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sideshowbarker
Copy link
Member

For web compat and for interop with actual behavior in browsers, this change updates the spec to require firing keypress events for the Enter key and for the combination of the Enter key with the Shift or Ctrl keys.

Otherwise, without this change, the spec is restricting implementations to requirements for keypress that are different from what browsers need to implement in order to be compatible with existing web content.

As an example of a specific case where conforming to the current spec causes unexpected behavior:

Without this change, Ladybird — which has strictly implemented the spec as currently written — doesn’t work as expected when trying to send messages in the The Lounge • https://thelounge.chat/ web-based IRC client.

And in troubleshooting that problem, I noticed that The Lounge is a Vue-based app — so, out of curiosity, I did a search at https://github.com/search?q=%22%40keypress.enter%22+language%3AVue&type=code&l=Vue and found that there’s a whole lotta other Vue code out there in the wild that’s doing stuff with @keypress.enter.

Closes #183, and closes #266.

The following tasks have been completed:

  • Confirmed there are no ReSpec/BikeShed errors or warnings.
    [There are existing errors; this change doesn’t introduce any new ones]
  • Modified Web platform tests (link to pull request)
    [I’m not aware of any WPT tests for this…]

Implementation commitment:

For web compat and interop with actual behavior in browsers, this change
updates the spec to require firing “keypress” events for the Enter key
and for the combination of the Enter key with the Shift or Ctrl keys.

Otherwise, without this change, the spec is restricting implementations
to requirements for keypress that are different from what browsers need
to implement in order to be compatible with existing web content.
sideshowbarker added a commit to mdn/content that referenced this pull request Jan 27, 2025
This change updates the page for the “keypress” event to match actual
behavior in browsers — by changing the page to state that the event
fires when the Enter key is pressed — not only when a key that produces
a character value is pressed.

See w3c/uievents#183 (comment)
and w3c/uievents#266 (comment)
and w3c/uievents#392

Otherwise, without this change, the information on the “keypress” page
incorrectly doesn’t match actual browser behavior — in that the page
states that the “keypress” event fires _only_ when a key that produces a
character value are pressed, while in fact browsers also fire the event
when the Enter key is pressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant