Skip to content
New issue

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

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

Already on GitHub? # to your account

Document that the Enter key causes the “keypress” event to fire #37817

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

sideshowbarker
Copy link
Member

@sideshowbarker sideshowbarker commented 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.

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.

@sideshowbarker sideshowbarker requested a review from a team as a code owner January 27, 2025 03:14
@sideshowbarker sideshowbarker requested review from wbamberg and removed request for a team January 27, 2025 03:14
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Jan 27, 2025
Copy link
Contributor

github-actions bot commented Jan 27, 2025

Preview URLs

External URLs (1)

URL: /en-US/docs/Web/API/Element/keypress_event
Title: Element: keypress event

(comment last updated: 2025-01-30 07:33:55)

@Josh-Cena
Copy link
Member

Josh-Cena commented Jan 29, 2025

Wait, but doesn't Enter also produce a printable character, i.e. the line break character? Is that not always the case?

@sideshowbarker sideshowbarker force-pushed the sideshowbarker/keypress-fires-for-Enter-key branch from 103abd4 to a2add09 Compare January 30, 2025 04:24
@sideshowbarker
Copy link
Member Author

Wait, but doesn't Enter also produce a printable character, i.e. the line break character?

Good point — the existing “key that produces a character value” language doesn’t actually have any clear and precise technical meaning. It’s ambiguous and misleading and unhelpful and we never should have been using it to begin with.

What the spec actually normatively defines it as is, “belonging to the set of valid Unicode character categories, where Unicode character categories is this:

the Letter (Ll, Lm, Lo, Lt, Lu), Number (Nd, Nl, No), Punctuation (Pc, Pd, Pe, Pf, Pi, Po, Ps) and Symbol (Sc, Sk, Sm, So) category values

So, I’ve amended the commit to excise the “key that produces a character value” language and instead — to match the actual normative spec requirements — explicitly and precisely just say, “a letter, number, punctuation, or symbol key”.

@Josh-Cena
Copy link
Member

Thanks! It's actually fine if you refer to those Unicode character categories explicitly, and link to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape. Makes the definition even less ambiguous.

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.
@sideshowbarker sideshowbarker force-pushed the sideshowbarker/keypress-fires-for-Enter-key branch from a2add09 to 703cb5c Compare January 30, 2025 07:32
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@Josh-Cena Josh-Cena merged commit b3c6c88 into main Feb 2, 2025
12 checks passed
@Josh-Cena Josh-Cena deleted the sideshowbarker/keypress-fires-for-Enter-key branch February 2, 2025 06:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants