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(runtime-dom): event handlers with modifiers should get all event arguments #1193

Merged
merged 1 commit into from May 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/runtime-dom/__tests__/directives/vOn.spec.ts
Expand Up @@ -118,4 +118,13 @@ describe('runtime-dom: v-on directive', () => {
expect(fn).toBeCalled()
})
})

it('should handle multiple arguments when using modifiers', () => {
const el = document.createElement('div')
const fn = jest.fn()
const handler = withModifiers(fn, ['ctrl'])
const event = triggerEvent(el, 'click', e => (e.ctrlKey = true))
handler(event, 'value', true)
expect(fn).toBeCalledWith(event, 'value', true)
})
})
4 changes: 2 additions & 2 deletions packages/runtime-dom/src/directives/vOn.ts
Expand Up @@ -26,12 +26,12 @@ const modifierGuards: Record<
* @internal
*/
export const withModifiers = (fn: Function, modifiers: string[]) => {
return (event: Event) => {
return (event: Event, ...args: unknown[]) => {
for (let i = 0; i < modifiers.length; i++) {
const guard = modifierGuards[modifiers[i]]
if (guard && guard(event, modifiers)) return
}
return fn(event)
return fn(event, ...args)
}
}

Expand Down