diff --git a/src/compiler/codegen/events.ts b/src/compiler/codegen/events.ts index 5ee53e54b17..aa99469497c 100644 --- a/src/compiler/codegen/events.ts +++ b/src/compiler/codegen/events.ts @@ -114,12 +114,13 @@ function genHandler( } } else if (key === 'exact') { const modifiers = handler.modifiers - genModifierCode += genGuard( - ['ctrl', 'shift', 'alt', 'meta'] - .filter(keyModifier => !modifiers[keyModifier]) - .map(keyModifier => `$event.${keyModifier}Key`) - .join('||') - ) + const condition = ['ctrl', 'shift', 'alt', 'meta'] + .filter(keyModifier => !modifiers[keyModifier]) + .map(keyModifier => `$event.${keyModifier}Key`) + .join('||') + if (condition) { + genModifierCode += genGuard(condition) + } } else { keys.push(key) } diff --git a/test/unit/features/directives/on.spec.ts b/test/unit/features/directives/on.spec.ts index e103301471e..38dd82b5733 100644 --- a/test/unit/features/directives/on.spec.ts +++ b/test/unit/features/directives/on.spec.ts @@ -324,6 +324,34 @@ describe('Directive v-on', () => { expect(spy.mock.calls.length).toBe(1) }) + // #12319 + it('should support all system modifiers with exact', () => { + vm = new Vue({ + el, + template: ` +
+ +
+ `, + methods: { foo: spy } + }) + + // should not trigger without all modifiers + triggerEvent(vm.$refs.input, 'keydown', e => { + e.ctrlKey = true + }) + expect(spy.mock.calls.length).toBe(0) + + // should trigger with all modifiers + triggerEvent(vm.$refs.input, 'keydown', e => { + e.ctrlKey = true + e.shiftKey = true + e.altKey = true + e.metaKey = true + }) + expect(spy.mock.calls.length).toBe(1) + }) + it('should support number keyCode', () => { vm = new Vue({ el, diff --git a/test/unit/modules/compiler/codegen.spec.ts b/test/unit/modules/compiler/codegen.spec.ts index aab2505f254..30b27272cf3 100644 --- a/test/unit/modules/compiler/codegen.spec.ts +++ b/test/unit/modules/compiler/codegen.spec.ts @@ -455,6 +455,11 @@ describe('codegen', () => { '', `with(this){return _c('input',{on:{"click":function($event){if(!$event.ctrlKey)return null;if($event.shiftKey||$event.altKey||$event.metaKey)return null;return onClick.apply(null, arguments)}}})}` ) + // #12319 + assertCodegen( + '', + `with(this){return _c('input',{on:{"keydown":function($event){if(!$event.ctrlKey)return null;if(!$event.shiftKey)return null;if(!$event.altKey)return null;if(!$event.metaKey)return null;return onClick.apply(null, arguments)}}})}` + ) }) it('generate events with multiple modifiers', () => {