-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to track the current item in focus after focus loss #25
Comments
Hello @Anonymous-NewBee! Sorry to hear you're having some issues, but I will try to offer some suggestions to help you out:
These in themselves can be very helpful, but I will assume that you have already tried using these. Since the issue is that you are unsure which DOM element corresponds to which focusable element, I would try to add fixed (statically named) focus-key values to your focusable components: https://github.com/NoriginMedia/Norigin-Spatial-Navigation/#focuskey-optional Using this you could create focus-key values that are easy to trace, for example something like I will close this on the assumption that this will help you resolve your issue. Feel free to reopen it if you need further input. Best of luck to you and happy coding! |
I'm also having problems with focus loss/stuck Judging by (I've already tried calling root element's |
@zemlanin: Hello again 👋 This sounds really strange to me. We are using this in several production apps and have not experienced any such issues. I assume there is more to it - If you could please provide an example where this issue can be reproduced, then we will look into it. Thanks. |
Yeah, hi :) I'll keep looking for an isolated reproduction case, but it seems to be related to Maybe, some "funny" interaction with |
Seems like it is a funny interaction with Anyways, here's a repro: https://github.com/zemlanin/lost-focus-bug |
Hi. Any updates regarding reproduction case? |
The reproduction case works fine in desktop Chrome but fails in Safari — cleanup function of Unsure if that's what also happening for me on TVs, will keep digging… |
As a workaround, the reseting spatial navigation service (by calling |
Hello @zemlanin. Sorry for not getting back to you on this as quickly as I had wanted, but I have personally been quite busy these last few weeks. Also again, sorry to hear you're having these issues with the hook - To me it kind of looks like this is happening when used in combination with react-router v6, as you mentioned. Generally I would like to try to avoid needing to make changes in relation to exposing lots of the internal functions of the service, as it should work without needing to do things like manually calling We need to fix this in the library (in a good way), if we can. Exposing internal or additional functionalities should be more of an "extra" to account for some edge-case or add some more functionality, more so than "we literally cannot use this library without calling these functions ourselves". As such, I will ping @asgvard on this one, in case he has time to look into this, as I will be even busier for the next few days. |
This might be related?.. https://github.com/NoriginMedia/Norigin-Spatial-Navigation/blob/dbf9a315f2dce2b42ed8c882c95419d9942a703c/src/useEffectOnce.ts @asgvard Was this hook introduced only to fix |
First of all, thanks @zemlanin for sharing this example code. That was very useful to reproduce the issue you were mentioning. So as you mentioned, that issue was reproducible on Safari. However deep in the code you shared, I found that there was repeated It is a fair point that there is no mention at the docs page that the Let me know if that works for you as well |
Ahhh… Thanks 🙏 I'll try it next week For what it worth, it seems, at least initially, very strange to assign different |
Still trying, but I might have found another "lost focus" case: zemlanin/lost-focus-bug@8f055fe
When container with a focused child is removed from DOM, the library should focus on a container's parent, shouldn't it? ( |
And another: zemlanin/lost-focus-bug@0e3bcd2
Removing set function Root() {
const location = useLocation()
const focusKey = someFn(location)
return <main>
<Sidebar contentFocusKey={focusKey} />
<Content focusKey={focusKey} />
</main>
}
function Sidebar({ contentFocusKey }) {
const { ref, setFocus } = useFocusable({
focusKey: contentFocusKey + '-sidebar'
})
function someCallback() {
setFocus(contentFocusKey)
}
// ...
}
function Content({ focusKey }) {
const { ref } = useFocusable({
focusKey: focusKey
})
// ...
} (as a workaround, reorganized |
Thanks for the input on these issues, @zemlanin, we really appreciate it. 🙇 I'll make sure we get these looked into and provide some feedback and / or fixes. |
Seems to be fixable with these lines in const children = filter(
this.focusableComponents,
(component) =>
component.parentFocusKey === focusKey && component.focusable
);
if (children.length) {
forEach(children, (child) => {
// eslint-disable-next-line no-param-reassign
child.parentFocusKey = parentFocusKey;
});
} |
And this one is fixable in app code via setting different <Routes>
<Route path="/" element={<RootView key="root" />} />
<Route path="/similar" element={<RootView key="similar" />} />
</Routes> But the fix for parameterized paths, like |
Thanks @zemlanin for your contribution.
This was updated in the last version based on your suggestion.
Based on what I see here, there is no creation of new focusables when entering the "similar" page. As far as I can see, the RootView is not unmounted (root) -> mounted (similar) when the location is changed. That means that entering a new page, keeps the old |
Thank you
If I read |
Did you find a good way to go around the problem of routing and this library? I am having a similar focus problem when using react-router-dom, especially when the application is run on older TV's (Tizen 5.0, 5.5, 6.0). I have reproduced this bug by adding routing to the library example: Routing looses focus. I have also added more assets to up the number of rendered elements in the DOM. It seems (just like zemlanin) that the focused element is an element that is no longer in the DOM. |
I am going to close this issue as it's not been updated for a longer period. When it comes to loss of focus there's been a release to add some improvements as to how to detect that: https://github.com/NoriginMedia/Norigin-Spatial-Navigation/releases/tag/v2.0.0 Hopefully this will help resolve the issues you guys are seeing; If not then please open a new issue with the specific problem you are having and we can discuss it accordingly. |
Is your feature request related to a problem? Please describe.
We are using Norigin Media for smart tv app development.
One issue we keep of facing is loss of focus because of incorrect code and from the logs we are unable to track how to find out the current item in focus.
e.g.
So even though now that we have lost focus and current focussed item is sn:focusable-item-1, we are unable to locate which item in DOM corresponds to this element
Describe the solution you'd like
Is there a way we can track the currently focussed item in DOM, so that we can track why it is focussed now. E.g. if we can log the entire focussable tree in console or see the focused item (sn:focusable-item-1) in DOM so that developer can debug the issue better?
Please also suggest is there any other way to solve this problem which we may have missed out
The text was updated successfully, but these errors were encountered: