Skip to content
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

Route with keepAlive: true does not fire its focus hook when coming back to the kept alive instance #221

Closed
ChrisArasin opened this issue Nov 15, 2024 · 6 comments

Comments

@ChrisArasin
Copy link

ChrisArasin commented Nov 15, 2024

I'm finding that if I have keepAlive: true on a route, navigate away from it, then navigate back, the focus hook does not fire on the page component. This means the proper child component on the page does not get refocused.

@ChrisArasin ChrisArasin changed the title Route with keepAlive: true does not fire it's focus hook when coming back to the kept alive instance Route with keepAlive: true does not fire its focus hook when coming back to the kept alive instance Nov 15, 2024
@michielvandergeest
Copy link
Collaborator

hey @ChrisArasin, the Portal page in the Blits example page has keep alive on it and it seems to work properly wiht passing the focus back to the previously focused item. It fires the focus hook on the item that was focused before navigating, but it indeed does not fire a focus event on the parent (or grand grand parents) of the item component.

Can you provide some details / examples how a focus event on the parent page (or other parent components) would be necessary ?

@ChrisArasin
Copy link
Author

Ah I see, was expecting to see the focus event fire from top down...

I've got a page using something based on the List component: https://github.com/lightning-js/blits-components/blob/main/src/components/List.js.

If only the child focused element has focus fire when returning to the page, the scrollToFocus handling in List will not trigger. Could probably design around that if need be though...

The main thing I noticed was my focus state on the child element not displaying. Oddly enough it seems like even though I see the focus hook fire, $hasFocus does not flip to true

Can see here, if you press enter to route to another page, then delete to go back to the kept alive page, rather than the box being red both times, it's blue the second time.

https://playground.lightningjs.io/#3tO5Igx4Saci

@michielvandergeest
Copy link
Collaborator

Hey @ChrisArasin, you are right about the $hasFocus property not being set when navigating back via the router. We' should have fixed that part in this commit: #225, which should land in the next release

Does this also fix your initial issue?

@ChrisArasin
Copy link
Author

Awesome! Yes, that should fix the visual bug I was encountering.

@michielvandergeest
Copy link
Collaborator

Cool! Good to hear :)

So you think we can close this issue? Or shall we keep it around, to see if we need to further address the hooks firing?

I still don't really think that it should fire the whole chain again, as the page is kept alive. So the only thing it should then do is ensure that the previously focused component, receives back it's focus, right?

But happy to hear if we've missed a use case or angle.

@ChrisArasin
Copy link
Author

ChrisArasin commented Nov 25, 2024

Yeah, I could go either way, but #163 seems to cover that for now. But yeah, we can go ahead and close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants