I want to be able to interact with a pull down menu only on keyboard. In Chrome it works well, but on Firefox doesn't work. Keyboard input I want to work:
'Tab' (menu is focused, it works)
--> 'Enter' (menu pulled down, it works)
--> 'Tab' to select a menu item fails
--> 'Enter' to check menu item
HTML:
<div id="headerbuttons" class="loggedin">
<div tabindex="0" class="button user css-onclick-menu">
<span class="username" title="TESTUSER">
<div class="icon"></div>
TESTUSER
</span>
<ul class="css-onclick-content">
<li>
<a href="/bookmark/check">add bookmark</a>
</li>
<li>
<a href="/user">my profile</a>
</li>
<li>
<a href="/ettutorials">tutorials</a>
</li>
</ul>
</div>
</div>
JS:
(function ($) {
"use strict";
$(document).ready(function () {
$('.css-onclick-menu .username').on('click', function() {
toggleUserMenu($('.user .css-onclick-content'));
});
$('.button.user.css-onclick-menu').keypress(function (e) {
let key = e.which;
if(key == 13) {
toggleUserMenu($('.user .css-onclick-content'));
}
});
var toggleUserMenu = function($content) {
if($content.css('display') == 'block') {
$content.css('display', 'none');
} else {
$content.css('display', 'block');
}
}
});
})(jQuery);
Minimal CSS
.css-onclick-content {
display: none;
top: 9px;
}
To play around in JsFiddle with fancier CSS:
https://jsfiddle.net/0L64ktw1/1/
I have tried to set tabindex=0
on <li>
and <a>
but it doesn't work like expected.
Thank you.