Search code examples
javascripteventsember.jskeypress

EmberJS requiredKeys for action


How can I define an action (on click) which is only call when a specific modifier key is pressed?

allowedKeys also executes the action when no modifier keys are pressed.


Solution

  • One approach will be just do

    <div onclick={{action 'itemClick'}}> my item </div>  
    

    and in your controller/parent component

    actions: {
      itemClick(e){
        if (e.altKey) {
           // alt key 
        } else if (e.ctrlKey) {
           // ctrl key 
        }
      }
    }