I was stuck in figuring out the logic to make an accessible keyboard with a drop down menu.
HTML is structured as such (additional class names are used for clarity):
<ul> <li class="primaryMenuItem"> <a href="">Link 1</a> <ul class="popUpMenu"> <li><a href="">Sub Link 1</a></li> <li><a href="">Sub Link 2</a></li> </ul> </li> <li class="primaryMenuItem"> <a href="">Link 2</a> <ul class="popUpMenu"> <li><a href="">Sub Link 1</a></li> <li><a href="">Sub Link 2</a></li> </ul> </li> </ul>
Link 1 and link 2, when they freeze, will display lists of submenus (drop-down menu). This works fine for me with some jQuery and the jQuery hoverIntent plugin.
The trick is that this only works with the mouse at the moment.
The next task is to make it work from the keyboard.
I can easily add a focus event to the top-level links, which then trigger the secondary menus:
$('ul.primaryMenuItem a:first').focus([call showMenu function])
It works great.
To close the menu, when you open another menu, select one of the options to check if there is another open and, if so, close it.
This also works great.
However, if this fails, it is if you open the last menu and exit it. Since you have not entered another menu, it remains open.
The task is to figure out how / when you need to close the menu and the necessary logic (jQuery) to understand this. Ideally, I would close the menu when the focus is on the item on the OTHER page than any child menu items.
Logically, I am looking for this:
$('li.primaryMenuItem').blur([close $(this).find('ul.popUpMenu'))
However, you cannot do this because the LI does not actually have a focus, but rather a snap tag inside it.
Any suggestions?
UPDATE:
perhaps a better / simpler way to ask a question:
Is there a way to βlookβ through jQuery to see if the focus has been moved beyond all the children of a particular object?