@@ -20,6 +20,7 @@ export default class ContextMenuTrigger extends Component {
2020 PropTypes . node ,
2121 PropTypes . func
2222 ] ) ,
23+ mouseButton : PropTypes . number ,
2324 disableIfShiftIsPressed : PropTypes . bool
2425 } ;
2526
@@ -31,6 +32,7 @@ export default class ContextMenuTrigger extends Component {
3132 renderTag : 'div' ,
3233 posX : 0 ,
3334 posY : 0 ,
35+ mouseButton : 2 , // 0 is left click, 2 is right click
3436 disableIfShiftIsPressed : false
3537 } ;
3638
@@ -90,10 +92,19 @@ export default class ContextMenuTrigger extends Component {
9092 }
9193
9294 handleContextMenu = ( event ) => {
93- this . handleContextClick ( event ) ;
95+ if ( event . button === this . props . mouseButton ) {
96+ this . handleContextClick ( event ) ;
97+ }
9498 callIfExists ( this . props . attributes . onContextMenu , event ) ;
9599 }
96100
101+ handleMouseClick = ( event ) => {
102+ if ( event . button === this . props . mouseButton ) {
103+ this . handleContextClick ( event ) ;
104+ }
105+ callIfExists ( this . props . attributes . onClick , event ) ;
106+ }
107+
97108 handleContextClick = ( event ) => {
98109 if ( this . props . disable ) return ;
99110 if ( this . props . disableIfShiftIsPressed && event . shiftKey ) return ;
@@ -144,6 +155,7 @@ export default class ContextMenuTrigger extends Component {
144155 const newAttrs = assign ( { } , attributes , {
145156 className : cx ( cssClasses . menuWrapper , attributes . className ) ,
146157 onContextMenu : this . handleContextMenu ,
158+ onClick : this . handleMouseClick ,
147159 onMouseDown : this . handleMouseDown ,
148160 onMouseUp : this . handleMouseUp ,
149161 onTouchStart : this . handleTouchstart ,
0 commit comments