File tree 3 files changed +32
-5
lines changed
test/unit/features/directives
3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,25 @@ const modifierCode: { [key: string]: string } = {
34
34
right : genGuard ( `'button' in $event && $event.button !== 2` )
35
35
}
36
36
37
- export function genHandlers ( events : ASTElementHandlers , native ? : boolean ) : string {
37
+ export function genHandlers (
38
+ events : ASTElementHandlers ,
39
+ native : boolean ,
40
+ warn : Function
41
+ ) : string {
38
42
let res = native ? 'nativeOn :{ ' : 'on :{ '
39
43
for ( const name in events ) {
40
- res += `"${name } ":${genHandler ( name , events [ name ] ) } , `
44
+ const handler = events [ name ]
45
+ // #5330: warn click.right, since right clicks do not actually fire click events.
46
+ if ( process . env . NODE_ENV !== 'production' &&
47
+ name === 'click' &&
48
+ handler && handler . modifiers && handler . modifiers . right
49
+ ) {
50
+ warn (
51
+ `Use "contextmenu" instead of "click.right" since right clicks ` +
52
+ `do not actually fire "click" events.`
53
+ )
54
+ }
55
+ res += `"${name } ":${genHandler ( name , handler ) } , `
41
56
}
42
57
return res.slice(0, -1) + '}'
43
58
}
Original file line number Diff line number Diff line change @@ -205,10 +205,10 @@ function genData (el: ASTElement): string {
205
205
}
206
206
// event handlers
207
207
if ( el . events ) {
208
- data += `${ genHandlers ( el . events ) } ,`
208
+ data += `${ genHandlers ( el . events , false , warn ) } ,`
209
209
}
210
210
if ( el . nativeEvents ) {
211
- data += `${ genHandlers ( el . nativeEvents , true ) } ,`
211
+ data += `${ genHandlers ( el . nativeEvents , true , warn ) } ,`
212
212
}
213
213
// slot target
214
214
if ( el . slotTarget ) {
Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ describe('Directive v-on', () => {
4
4
let vm , spy , el
5
5
6
6
beforeEach ( ( ) => {
7
+ vm = null
7
8
spy = jasmine . createSpy ( )
8
9
el = document . createElement ( 'div' )
9
10
document . body . appendChild ( el )
10
11
} )
11
12
12
13
afterEach ( ( ) => {
13
- document . body . removeChild ( vm . $el )
14
+ if ( vm ) {
15
+ document . body . removeChild ( vm . $el )
16
+ }
14
17
} )
15
18
16
19
it ( 'should bind event to a method' , ( ) => {
@@ -548,4 +551,13 @@ describe('Directive v-on', () => {
548
551
triggerEvent ( vm . $refs . input , 'keydown' , e => { e . keyCode = 13 } )
549
552
expect ( prevented ) . toBe ( true )
550
553
} )
554
+
555
+ it ( 'should warn click.right' , ( ) => {
556
+ new Vue ( {
557
+ template : `<div @click.right="foo"></div>` ,
558
+ methods : { foo ( ) { } }
559
+ } ) . $mount ( )
560
+
561
+ expect ( `Use "contextmenu" instead` ) . toHaveBeenWarned ( )
562
+ } )
551
563
} )
You can’t perform that action at this time.
0 commit comments