fix(trigger): set spec-compliant event.code on keydown/keyup#2850
Merged
Conversation
…ey modifiers
`trigger('keydown.enter')` previously set `event.code` to the numeric
keyCode (e.g. 13) instead of the W3C string identifier (`Enter`). Add a
`codesByKeyName` map alongside `keyCodesByKeyName` and use it for `code`
when a key modifier is present. The numeric `keyCode` fallback is kept
for callers that pass `{ keyCode }` without a modifier, so existing
behavior is unchanged.
Closes vuejs#2544
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
Contributor
Author
Thanks for the quick review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2544.
trigger('keydown.enter') (and other keydown/keyup modifiers) was setting event.code to the numeric keyCode (e.g. 13) instead of the W3C UI Events string identifier ("Enter"). Tests checking event.code for accessibility/keyboard-navigation handlers couldn't pass because of this.
Change
Added codesByKeyName next to keyCodesByKeyName in src/constants/dom-events.ts, mapping every supported key modifier to its W3C code string.
createDomEvent.ts now picks event.code from codesByKeyName when a key modifier is present. Explicit options.code still takes priority. The numeric keyCode fallback is kept for legacy callers that pass { keyCode } without a modifier, so existing behavior is unchanged.
Coverage
Added a sibling test in tests/trigger.spec.ts (next to the existing keyCode-mapping test) that iterates codesByKeyName and asserts the handler receives the correct event.code string for every modifier.
Affected modifiers: backspace, tab, enter, esc, space, pageup, pagedown, end, home, left, up, right, down, insert, delete.