diff --git a/packages/lib/src/spatial-navigation/SpatialNavigator.ts b/packages/lib/src/spatial-navigation/SpatialNavigator.ts index 8ea8c7c9..47743f72 100644 --- a/packages/lib/src/spatial-navigation/SpatialNavigator.ts +++ b/packages/lib/src/spatial-navigation/SpatialNavigator.ts @@ -110,9 +110,13 @@ export default class SpatialNavigator { * * Still, I want to queue it, because the element might not be registered yet (example: in the case of virtualized lists) */ - public queueFocus = (id: string) => { - if (this.focusQueue) return; - this.focusQueue = id; + public deferredFocus = (id: string) => { + setTimeout(() => { + if (this.lrud.getNode(id)) { + this.lrud.assignFocus(id); + return; + } + }, 0); }; /** diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedListWithScroll.tsx b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedListWithScroll.tsx index 08cda439..a216c07e 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedListWithScroll.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedListWithScroll.tsx @@ -202,7 +202,7 @@ export const SpatialNavigationVirtualizedListWithScroll = typedMemo( setCurrentlyFocusedItemIndex(index); if (idRef.current) { const newId = idRef.current.getNthVirtualNodeID(index); - spatialNavigator.queueFocus(newId); + spatialNavigator.deferredFocus(newId); } }, }),