NoriginMedia / react-spatial-navigation

DEPRECATED. HOC-based Spatial Navigation. NEW Hooks version is available here: https://github.com/NoriginMedia/norigin-spatial-navigation
MIT License
226 stars 64 forks source link

A way to find the currently focused item. #44

Closed stuartflanagan closed 1 year ago

stuartflanagan commented 5 years ago

Is your feature request related to a problem? Please describe. A way to find the currently focused item. This may already be available I am just not sure of the API to surface it sorry.

Describe the solution you'd like SpatialNavigation.currentlyFocusedItem()

I am trying to find a way to get the currently focused item to return to after certain warnings or actions.

Is there a way to retrieve the current withFocusable item that is in focus from the library?

stuartflanagan commented 4 years ago

Any updates on how this can be achieved from the API would be very helpful

asgvard commented 4 years ago

Hi! This is on our radar, we also had some use cases where we need to know the focus key of currently focused item (or other information about it). So I hope it will be added soon.

stuartflanagan commented 4 years ago

Thank you for responding! I will keep an eye out.

MarcoFiusco commented 4 years ago

Hi, any news on this topic? Thanks

asgvard commented 4 years ago

Hi,

Sorry, nothing new so far, as we still didn't have real use case where we need to know the currently focused item. Usually the item itself getting focused flag is more than enough. Or in case of parent items - hasFocusedChild. But feel free to make a PR. There is similar PR #52 however it implies exporting the whole instance of SpatialNavigation, which could be a bit dangerous since you can basically execute any method from it manually as there are no "private" methods then. So perhaps the better solution would be to export simple method that will get currently focused item, together with the global methods exported from the lib like initNavigation etc. from index.js.