luke-chang / js-spatial-navigation

A javascript-based implementation of Spatial Navigation.
Mozilla Public License 2.0
370 stars 117 forks source link

how to keep two elements on focus (menu item and submenu item) #28

Closed shaikzubeer1 closed 6 years ago

shaikzubeer1 commented 6 years ago

Hi @luke-chang , how to keep two elements on focus ? suppose i select an item from menu, sub-menu to that item opens, i want to keep menu item highlighted/focused as long as i get a key event from sub-menu item. Is there a way to keep both menu and sub-menu item focused ??

Thanks, zubeer

luke-chang commented 6 years ago

SpatialNavigation doesn't maintain the focus. It only takes care of what the next item is. You probably have noticed that the focus can be changed by mouse as well and SpatialNavigation can work with the new focused element without problems.

That is to say, the focus is actually maintained by the browser itself and SpatialNavigation only helps to move the focus to the next element according to the currently-focused one. It doesn't make sense to calculate the next item based on two different sources (and actually browsers can't let you keep two focuses).

If what you want is to have two elements highlighted at the same time, you can definitely do it by CSS regardless of the focus. It is out of the scope of SpatialNavigation though.

shaikzubeer1 commented 6 years ago

That's very helpful @luke-chang .

Thanks allot, zubeer