Skip to content

Commit ab86b19

Browse files
authored
fix(runtime-dom): event handlers with modifiers should get all event arguments (#1193)
1 parent d73a508 commit ab86b19

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/runtime-dom/__tests__/directives/vOn.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,13 @@ describe('runtime-dom: v-on directive', () => {
118118
expect(fn).toBeCalled()
119119
})
120120
})
121+
122+
it('should handle multiple arguments when using modifiers', () => {
123+
const el = document.createElement('div')
124+
const fn = jest.fn()
125+
const handler = withModifiers(fn, ['ctrl'])
126+
const event = triggerEvent(el, 'click', e => (e.ctrlKey = true))
127+
handler(event, 'value', true)
128+
expect(fn).toBeCalledWith(event, 'value', true)
129+
})
121130
})

packages/runtime-dom/src/directives/vOn.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const modifierGuards: Record<
2626
* @internal
2727
*/
2828
export const withModifiers = (fn: Function, modifiers: string[]) => {
29-
return (event: Event) => {
29+
return (event: Event, ...args: unknown[]) => {
3030
for (let i = 0; i < modifiers.length; i++) {
3131
const guard = modifierGuards[modifiers[i]]
3232
if (guard && guard(event, modifiers)) return
3333
}
34-
return fn(event)
34+
return fn(event, ...args)
3535
}
3636
}
3737

0 commit comments

Comments
 (0)