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

Question RE: remembering focus state of screen #42

Closed stuartflanagan closed 5 years ago

stuartflanagan commented 5 years ago

I have a small application set up at the moment with some routing in place to navigate screens. Just using react-router: 5.0.0 at the moment.

My question is on how I might retain state of focus between component rendering. If I am on a category page with some rows like your example application and I navigate away from this screen does the inbuilt focus state persistence of child components still function?

I am asking as i am having trouble getting this to remember focus state of parents and child components when returning from another route.

Thanks for all the work you have put into this library.

asgvard commented 5 years ago

Hi!

To solve this use case we usually save the “last focused row/item” in the parent state (e.g. redux) when the page is unmounted. Then when mounted again, we focus that element by its row/item indices. To do that we also need to know focus keys, so remember to set them for each row and item. Since this logic is out of scope of this library, this needs to be handled by the application. This library remembers last focused elements only within one lifecycle.

Closing this as answered, please feel free to reopen if you need more help.