NoriginMedia / Norigin-Spatial-Navigation

React Hooks based Spatial Navigation (Key & Remote Control Navigation) / Web Browsers, Smart TVs and Connected TVs
MIT License
315 stars 94 forks source link

Fixing focus restoration for added children #98

Closed adrian-wozniak closed 12 months ago

adrian-wozniak commented 1 year ago

Issue: Focus is not properly restored to preferredChildFocusKey when focusable is created.

It may happen that focusable element that should be focused is created later that focus to it is set. In such case addFocusable restores focus when it finds that just adding element should be focused. Such restoration should take into consideration the fact, that added focusable may be treated just as a container and is designed to move focus to its preferred child (which, again, might not be created yet). This is to make setFocus behavior consistent with situation when executed having all elements fully rendered.

Video below shows:

https://github.com/NoriginMedia/Norigin-Spatial-Navigation/assets/13609312/4a9db099-2256-4249-b5ec-38d7ac919324

Expected behavior - r15 focused on pressing enter on r00:

https://github.com/NoriginMedia/Norigin-Spatial-Navigation/assets/13609312/52231d8c-45d4-4080-af5c-eab492f42470