5

How to detect Click + [Shift, Ctrl, Alt] in the click event of reacjs?

 3 years ago
source link: https://www.codesd.com/item/how-to-detect-click-shift-ctrl-alt-in-the-click-event-of-reacjs.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to detect Click + [Shift, Ctrl, Alt] in the click event of reacjs?

advertisements

I want to do some other things when user Click+[Ctrl], but it seems that I could not detect if user press Ctrl when clicking.

I copy the event object infos below.

bubbles    :    false
cancelBubble    :    false
cancelable    :    false
currentTarget    :    react
defaultPrevented    :    false
eventPhase    :    2
isTrusted    :    false
path    :    Array[1]
returnValue    :    true
srcElement    :    react
target    :    react
timeStamp    :    5690056.695
type    :    "react-click"

I can see the ctrlKey attribute in the arguments[0]-Proxy Object. But this object is unaccessable('Uncaught illegal access'):

[[Target]]
:
SyntheticMouseEvent
_dispatchInstances:ReactDOMComponent
_dispatchListeners:(e)
_targetInst:ReactDOMComponent
altKey:false
bubbles:true
button:0
buttons:0
cancelable:true
clientX:275
clientY:315
ctrlKey:false


Your click handling function would have a format as such:

clickHandler: function (event, value) {

   event.stopPropagation();

   // In that case, event.ctrlKey does the trick.
   if (event.ctrlKey) {
        console.debug("Ctrl+click has just happened!");
   }
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK