From c6d7a6fce795ffbd6b8a599787eca986bb260a25 Mon Sep 17 00:00:00 2001 From: Mattia Trapani Date: Fri, 16 Apr 2021 17:53:45 +0200 Subject: [PATCH] fix(v-on): avoid events with empty keyCode (autocomplete) (#11326) --- src/core/instance/render-helpers/check-keycodes.js | 1 + test/unit/features/directives/on.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/core/instance/render-helpers/check-keycodes.js b/src/core/instance/render-helpers/check-keycodes.js index c12402b1..02613d4d 100644 --- a/src/core/instance/render-helpers/check-keycodes.js +++ b/src/core/instance/render-helpers/check-keycodes.js @@ -31,4 +31,5 @@ export function checkKeyCodes ( } else if (eventKeyName) { return hyphenate(eventKeyName) !== key } + return eventKeyCode === undefined } diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index 95693c19..7c252031 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -976,6 +976,17 @@ describe('Directive v-on', () => { expect(value).toBe(1) }) + it('should not execute callback if modifiers are present', () => { + vm = new Vue({ + el, + template: '', + methods: { foo: spy } + }) + // simulating autocomplete event (Event object with type keyup but without keyCode) + triggerEvent(vm.$el, 'keyup') + expect(spy.calls.count()).toBe(0) + }) + describe('dynamic arguments', () => { it('basic', done => { const spy = jasmine.createSpy()