lundi 25 janvier 2021

Javascript on-click handler, how to check if clicked by mouse or keydown?

I have an ember.js application with a button with an on-click method. For the purpose of accessibility I need to tell if the button was clicked by a standard mouse click or by the user hitting enter with the button focused. As a very basic idea:

onClickMethod() {
    doSomeStuff();
    if (buttonWasClickedByMouse) {
        doMouseThing();
    } else {
        doKeyDownThing();
    }
}

Is there a good way in Javascript to get this? I looked into originalEvent.detail, but that seems to be jQuery rather.




Aucun commentaire:

Enregistrer un commentaire