From de4f81577598af7e7dca3af38387f1e19ba78ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20L=C3=B3pez?= Date: Fri, 25 Sep 2026 12:04:24 +0200 Subject: [PATCH 1/2] fix: ensure the preferredChildFocusKey is actually a descendant of the current target --- packages/core/src/SpatialNavigation.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/core/src/SpatialNavigation.ts b/packages/core/src/SpatialNavigation.ts index 112a2be..927e7e6 100644 --- a/packages/core/src/SpatialNavigation.ts +++ b/packages/core/src/SpatialNavigation.ts @@ -1432,7 +1432,8 @@ export class SpatialNavigationService { */ if ( preferredChildFocusKey && - this.isParticipatingFocusableComponent(preferredChildFocusKey) + this.isParticipatingFocusableComponent(preferredChildFocusKey) && + this.isDescendantOf(preferredChildFocusKey, targetFocusKey) ) { this.log( 'getNextFocusKey', @@ -1770,6 +1771,24 @@ export class SpatialNavigationService { ); } + /** + * Checks whether the focusableComponent is a descendant of another component. + * @param focusKey The focus key of the component to check + * @param ancestorFocusKey The focus key of the ancestor component + * @returns Whether the focusableComponent is a descendant of the ancestor component + */ + isDescendantOf(focusKey: string, ancestorFocusKey: string): boolean { + let currentComponent = this.focusableComponents[focusKey]; + while (currentComponent) { + if (currentComponent.parentFocusKey === ancestorFocusKey) { + return true; + } + currentComponent = + this.focusableComponents[currentComponent.parentFocusKey]; + } + return false; + } + onIntermediateNodeBecameFocused( focusKey: string, focusDetails: FocusDetails From 92028466a517a05e7f31cb399189c2d9dd691900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20L=C3=B3pez?= Date: Fri, 25 Sep 2026 12:21:03 +0200 Subject: [PATCH 2/2] Prevent focus key from moving outside target subtree --- .changeset/goofy-ways-mix.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/goofy-ways-mix.md diff --git a/.changeset/goofy-ways-mix.md b/.changeset/goofy-ways-mix.md new file mode 100644 index 0000000..c91715a --- /dev/null +++ b/.changeset/goofy-ways-mix.md @@ -0,0 +1,5 @@ +--- +"@noriginmedia/norigin-spatial-navigation-core": patch +--- + +Prevent preferredChildFocusKey from moving focus outside the current target’s subtree