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

FIX 2433: preserve code from keyboard events #2434

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/createDomEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function getEventProperties(eventParams: EventParams) {
cancelable: meta.cancelable,
// Any derived options should go here
keyCode,
code: keyCode,
code: options.code || keyCode,
// if we have a `key`, use it, otherwise dont set anything (allows user to pass custom key)
...(keyModifiers[0] ? { key: keyModifiers[0] } : {})
}
Expand Down
15 changes: 15 additions & 0 deletions tests/trigger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ describe('trigger', () => {
expect(keydownHandler.mock.calls[0][0].keyCode).toBe(65)
})

it('causes keydown handler to fire with the appropriate code when wrapper.trigger("keydown", { code: "Space" }) is fired', async () => {
const keydownHandler = vi.fn()
const Component = {
template: '<input @keydown="keydownHandler" />',
methods: { keydownHandler }
}
const wrapper = mount(Component, {})
await wrapper.trigger('keydown', { code: 'Space', key: ' ', keyCode: 32 })

expect(keydownHandler).toHaveBeenCalledTimes(1)
expect(keydownHandler.mock.calls[0][0].key).toBe(' ')
expect(keydownHandler.mock.calls[0][0].code).toBe('Space')
expect(keydownHandler.mock.calls[0][0].keyCode).toBe(32)
})

it('causes keydown handler to fire converting keyName in an appropriate keyCode when wrapper.trigger("keydown.${keyName}") is fired', async () => {
let keydownHandler = vi.fn()

Expand Down