fix(webui): re-check focus before stealing it in DetailNavigationSheet

Stabilizes a flaky test ("does not yank focus onto a listbox option when
filteredItems shrinks"): the rAF that moves roving focus now re-checks
document.activeElement before calling focus(), so a focus bounce between
the effect's gate check and the next frame no longer steals focus.

Provisional: the race only reproduces under JSDOM focus simulation (not in
real browsers), so the proper fix likely belongs in the test layer — to be
revisited separately.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Sergey Kozyrenko
2026-06-12 17:40:41 +07:00
co-authored by Claude Fable 5
parent ed55924873
commit 5a7bdca4ac
@@ -173,6 +173,11 @@ export function DetailNavigationSheet<T extends { id: string }>({
}
const id = requestAnimationFrame(() => {
// Focus may have returned to the search input since the effect's gate check.
if (document.activeElement === searchInputRef.current) {
return;
}
const node = buttonRefs.current.get(focusedId);
if (!node) {