Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/compiler/codegen/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/directives/on.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
<div>
<input ref="input" @keydown.ctrl.shift.alt.meta.exact="foo">
</div>
`,
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,
Expand Down
5 changes: 5 additions & 0 deletions test/unit/modules/compiler/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ describe('codegen', () => {
'<input @click.ctrl.exact="onClick">',
`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(
'<input @keydown.ctrl.shift.alt.meta.exact="onClick">',
`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', () => {
Expand Down