You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: How can I detect modifier keys when a controlled <input type="checkbox" /> is clicked?
// Fires a "click" event with modifiers (e.shiftKey, etc):<inputtype="checkbox"onClick={e=>console.log('shiftKey'ine)}/>// "true"// Fires a "change" event WITHOUT modifiers (e.shiftKey, etc):<inputtype="checkbox"onClick={e=>console.log('shiftKey'ine)}checked/>// "false"
More details:
I want to be able to detect whether or not the Shift Key is pressed when a controlled checkbox is clicked.
The problem is that if the checked prop is passed to an input, then the onClick handler fires a "change" event instead of a "click" event. Unfortunately, "change" events don't have key modifier information.
FWIW, I've updated the example repository with a minimal example of the same thing using React, and the behaviour differs between React and Inferno (React provides the "click" event, so we can access key modifier information).
@acheronfail I didn't look into the code repo you provided yet. You could try using onclick={method} format instead of onClick this forces new click listener to be created on the html Node, non-synthetic event. Its less performant but that event will have the native click event for the given node.
TL;DR: How can I detect modifier keys when a controlled
<input type="checkbox" />
is clicked?More details:
I want to be able to detect whether or not the Shift Key is pressed when a controlled checkbox is clicked.
The problem is that if the
checked
prop is passed to an input, then theonClick
handler fires a"change"
event instead of a"click"
event. Unfortunately,"change"
events don't have key modifier information.Is this possible in some way?
I've made a minimal and reproducible example here: https://github.com/acheronfail/infernojs-checkbox-handler-example (
index.html
), if you run that and check the console you can see my problem.The text was updated successfully, but these errors were encountered: