react-tv-space-navigation icon indicating copy to clipboard operation
react-tv-space-navigation copied to clipboard

There should be a way for a leaf node to tell if it's SpatialNavigationRoot element has focus

Open jonp-iversoft opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe. When using Multiple SpatialNavigationRoot elements, there are multiple isFocused leaf nodes making a leaf node display itself as focused difficult.

Describe the solution you'd like I understand that each SpatialNavigationRoot does actually have a focused item local to itself, but the naming is confusing. There should be a way for a leaf of a SpatialNavigationRoot to see if it's parent SpatialNavigationRoot has focus

Describe alternatives you've considered We currently have separate SpatialNavigationRoot items for the menu, the content, and flyouts. We currently are using a menuContext to see if the menu SpatialNavigationRoot has focus or not. There should be a way for a button to tell if it's parent SpatialNavigationRoot has focus without importing a context from the menu.

jonp-iversoft avatar Apr 11 '24 18:04 jonp-iversoft

Hey!

That's an interesting point. We have a similar need, so we implemented a little context ourselves. I was wondering if it should be included in the lib itself.

What would you expect as an API? 😁

pierpo avatar Apr 12 '24 08:04 pierpo

Since there are already isActive and isFocused props being passed from a focusable SpatialNavigationNode maybe a isRootFocused could be added along?

jonp-iversoft avatar Apr 12 '24 15:04 jonp-iversoft

Would isRootActive be as clear? The root is not really focused (in LRUD we talk about focused for leaf nodes only if I'm correct 😁)

pierpo avatar Apr 12 '24 16:04 pierpo

yeah that works!

jonp-iversoft avatar Apr 12 '24 16:04 jonp-iversoft

Hey @jonp-iversoft ! I just opened a PR to solve your issue. I'm leaving for holidays, and I didn't want to leave you hanging.

If you want to try it out without a new release: you can clone the repo, build the lib using cd packages/lib && yarn build, copy the dist result in yourproject/node_modules/react-tv-space-navigation, and use patch-package react-tv-space-navigation to generate a patch out of it 😁 (well that's how I do it)

I tried it out a little bit, it seems to work fine 🙌 I'll try it more when I'll come back and publish it then.

pierpo avatar Apr 19 '24 17:04 pierpo

Published in 3.6.0 😊

pierpo avatar May 06 '24 13:05 pierpo

You're the 🐐

jonp-iversoft avatar May 06 '24 14:05 jonp-iversoft