Skip to content

Commit bec7a62

Browse files
author
Pierre Poupin
committed
fix(lists): fix imperative focus not always working on virtualized lists
1 parent 40689dc commit bec7a62

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/lib/src/spatial-navigation/SpatialNavigator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ export default class SpatialNavigator {
110110
*
111111
* Still, I want to queue it, because the element might not be registered yet (example: in the case of virtualized lists)
112112
*/
113-
public queueFocus = (id: string) => {
114-
if (this.focusQueue) return;
115-
this.focusQueue = id;
113+
public deferredFocus = (id: string) => {
114+
setTimeout(() => {
115+
if (this.lrud.getNode(id)) {
116+
this.lrud.assignFocus(id);
117+
return;
118+
}
119+
}, 0);
116120
};
117121

118122
/**

packages/lib/src/spatial-navigation/components/virtualizedList/SpatialNavigationVirtualizedListWithScroll.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export const SpatialNavigationVirtualizedListWithScroll = typedMemo(
202202
setCurrentlyFocusedItemIndex(index);
203203
if (idRef.current) {
204204
const newId = idRef.current.getNthVirtualNodeID(index);
205-
spatialNavigator.queueFocus(newId);
205+
spatialNavigator.deferredFocus(newId);
206206
}
207207
},
208208
}),

0 commit comments

Comments
 (0)