Skip to content

Commit f90d576

Browse files
committed
fix: retry giveFocus on next animation frame for newly created blocks
When a new block is created, giveFocus() may fail because the view's DOM element isn't mounted yet. This causes focus to fall back to the hidden dummy input, which cannot handle arrow key scrolling. Retry giveFocus() via requestAnimationFrame after the fallback, giving React a chance to flush pending renders before the retry. Fixes #2926 Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 8fc4dc3 commit f90d576

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

frontend/app/block/block.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => {
226226
return;
227227
}
228228
focusElemRef.current?.focus({ preventScroll: true });
229+
requestAnimationFrame(() => {
230+
viewModel?.giveFocus?.();
231+
});
229232
}, [viewModel]);
230233

231234
const focusFromPointerEnter = useCallback(

0 commit comments

Comments
 (0)