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

fix(lists): fix imperative focus not always working on virtualized lists #128

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/lib/src/spatial-navigation/SpatialNavigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
}),
Expand Down
Loading