Skip to content

Selecting checkbox while pressing the command/ctrl key #3402

Closed Answered by Lukas742
shivamdz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @shivamdz

the change event is a CustomEvent that doesn't hold the ctrlKey or metaKey information as it only inherits the properties of the Event type. This is similar to the native change event as it is as well only an Event.

So, to check whether CTRL or COMMAND is pressed (probably depending on OS), you need to register a global listener for it, then you can just update a React state depending on if one of the keys is pressed or not and check for that in your onChange callback.

https://codesandbox.io/s/command-ctrl-um916y?file=/src/App.js

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by shivamdz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants