I've got a page with a pretty standard popup menu in the header. The specs say that the user needs to be able to close it in three ways:
- by clicking outside the menu
- by clicking the link that expands it a second time (slidetoggle)
- by tabbing outside the menu
I have the first one working, but I can't seem to figure out the other two. When you click the link a second time, it slides up, and then slides back down. And I've tried using the jquery "focusout" to get the menu to close when the user tabs out, but no luck.
Here's my js:
$("#body").mouseup(function (e) {
var subject = $("#shell-user-account-details");
if (e.target.id != subject.attr('id') && !subject.has(e.target).length) {
subject.hide();
}
$("#shell-user-account-details").attr('aria-hidden', function (i, attr) {
return attr == 'true' ? 'false' : 'true';
}).attr('aria-expanded', function (i, attr) {
return attr == 'false' ? 'true' : 'false';
});
});
$(document).on('click', '#shell-user-account-link', function (event) {
$('#shell-user-account-details').slideToggle().attr('aria-expanded', function (i, attr) {
return attr == 'false' ? 'true' : 'false';
}).attr('aria-hidden', function (i, attr) {
return attr == 'false' ? 'true' : 'false';
})
});
And here's a Fiddle: https://jsfiddle.net/tactics/u4quaje0/2/
Thanks.