luke-chang / js-spatial-navigation

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

Adding/Removing elements from the dom #14

Closed safinn closed 7 years ago

safinn commented 7 years ago

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.

luke-chang commented 7 years ago

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.

safinn commented 7 years ago

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?

luke-chang commented 7 years ago

..., 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.)

safinn commented 7 years ago

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