Skip to content
Draft
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
7 changes: 6 additions & 1 deletion packages/react/src/TreeView/TreeView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function renderWithTheme(
ui: Parameters<typeof render>[0],
options?: Parameters<typeof render>[1],
): ReturnType<typeof render> {
return render(ui, options)
const result = render(ui, options)
// Flush deferred focus zone initialization (requestAnimationFrame)
act(() => {
vi.advanceTimersByTime(16)
})
return result
}

// Mock `scrollIntoView` because it's not implemented in JSDOM
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/hooks/useFocusZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ export function useFocusZone(
...settings,
activeDescendantControl: activeDescendantControlRef.current ?? undefined,
}
abortController.current = focusZone(containerRef.current, vanillaSettings)
const container = containerRef.current
const rafId = requestAnimationFrame(() => {
// Defer focus zone initialization to avoid blocking paint.
// Setting tabindex on focusable elements is invisible to the user,
// and keyboard navigation activating one frame later is imperceptible.
abortController.current = focusZone(container, vanillaSettings)
})
return () => {
cancelAnimationFrame(rafId)
abortController.current?.abort()
}
} else {
Expand Down
Loading