luke-chang / js-spatial-navigation

A javascript-based implementation of Spatial Navigation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding/Removing elements from the dom

safinn opened this issue · comments

Hello,

Just a quick question. If I was to add an element to the DOM that I wanted to be focusable with the correct class, what should I call to update the focusable elements that SpatialNavigation knows about?

Thank you.

Hi safinn,

Just want to make sure if you're saying "focusable" (an element can be focused) or "navigable" (an element can be navigated by SpatialNavigation).

For "focusable", you can simply call SpatialNavigation.makeFocusable(); again to make new elements become focusable (i.e. add "tabindex=-1" to them).

For "navigable", it depends on how you define the selector property. The added element should become navigable immediately if selector is set a CSS selector string and the element matches that string.

Feel free to let me know if I misunderstood your question.

Thank you for the reply. Right, I think I understand. So if I add the new element with the class name I used to make them "navigable", all I need to do is call SpatialNavigation.makeFocusable(); to make it "focusable"? Or do I not even need to do that?

..., all I need to do is call SpatialNavigation.makeFocusable(); to make it "focusable"

Correct!

Or set the tabindex attribute of the element by yourself (since that's all makeFocusable does.)

Awesome! Thanks for the help. Great library by the way.