Skip to content

Commit

Permalink
fix(runtime-dom): event handlers with modifiers should get all event …
Browse files Browse the repository at this point in the history
…arguments
  • Loading branch information
nekosaur committed May 15, 2020
1 parent e56d33e commit 7011bc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/runtime-dom/__tests__/directives/vOn.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7011bc5

Please sign in to comment.