WCAG 2.0 AA compliance requires, among other things, full support for keyboard only navigation of a web site. I am utilizing tabindex and role attributes to provide tab-key navigation to user. While implementing the accessibility features I came across following problem:
https://jsfiddle.net/fn9wvp1s/1/
<div id="app">
<div>
<button tabindex="1"
onclick="console.log('clicked')">
button
</button>
<div tabindex="2"
onclick="console.log('clicked')"
class="div-button"
role="button">
selectable div
</div>
</div>
</div>
Clicking the elements with a mouse naturally works, and click event is fired as expected. However, when using tab to navigate to the elements and hitting return/space, the event is only fired for the button. Why is this? Can I enable the click event from keyboard to the div element somehow?
I am quite aware of various workarounds, including binding key press event to the div. Ended up refactoring the markup and replacing the divs with buttons, but would still like to know why the thing is implemented this way.