Skip to content

Commit 38f51b0

Browse files
committed
feat($compile): Add .plain event modifier
Add a new event modifier `.plain` to check if event is "plain" (no shift/ctrl/meta/alt key is pressed) #5976
1 parent b5f08f3 commit 38f51b0

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/compiler/codegen/events.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const modifierCode: { [key: string]: string } = {
3131
meta: genGuard(`!$event.metaKey`),
3232
left: genGuard(`'button' in $event && $event.button !== 0`),
3333
middle: genGuard(`'button' in $event && $event.button !== 1`),
34-
right: genGuard(`'button' in $event && $event.button !== 2`)
34+
right: genGuard(`'button' in $event && $event.button !== 2`),
35+
plain: genGuard(`$event.ctrlKey || $event.shiftKey || $event.altKey || $event.metaKey`)
3536
}
3637

3738
export function genHandlers (

src/core/instance/proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (process.env.NODE_ENV !== 'production') {
2727
Proxy.toString().match(/native code/)
2828

2929
if (hasProxy) {
30-
const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta')
30+
const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,plain')
3131
config.keyCodes = new Proxy(config.keyCodes, {
3232
set (target, key, value) {
3333
if (isBuiltInModifier(key)) {

test/unit/modules/compiler/codegen.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ describe('codegen', () => {
298298
'<input @click.meta="onClick">',
299299
`with(this){return _c('input',{on:{"click":function($event){if(!$event.metaKey)return null;onClick($event)}}})}`
300300
)
301+
assertCodegen(
302+
'<input @click.plain="onClick">',
303+
`with(this){return _c('input',{on:{"click":function($event){if($event.ctrlKey || $event.shiftKey || $event.altKey || $event.metaKey)return null;onClick($event)}}})}`
304+
)
301305
})
302306

303307
it('generate events with multiple modifiers', () => {

0 commit comments

Comments
 (0)