JSFiddle - React, Tailwind, and code Playground

HTML

<p>Click the link below or tab onto it and press Enter.  Inside the event handler, I need to determine whether the mouse was clicked or ENTER was pressed.</p>
<p><a href="#" tabindex="1">Test</a></p>

CSS

p { margin-bottom: 1em; }

JavaScript

$("a").click(function(e, wasEnterKey) {
    if(wasEnterKey)
        alert("Enter key");
    else
        alert("Clicked");
});

$("a").keydown(function(e) {
  if(e.keyCode == 13) {
    $(this).trigger("click", true);
    e.preventDefault();
  }
});