Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: unit test the popover focus helpers

The helpers take the active element and body as arguments, so the cases
(focus into the box, keep a control that took focus, restore only when
focus was lost, find the trigger) run under node's test runner.
This commit is contained in:
iris 2026-10-21 22:44:44 +02:00 • committed by mara
commit 9338496e24

View file

@ -415,7 +415,7 @@ export function Table<T>({
useEffect(() => {
if (openFilterKey === null) return;
popoverControlRef.current?.focus();
focusInto(popoverRef.current);
focusInto(popoverRef.current, document.activeElement);
}, [openFilterKey]);
// After a close that left focus on nothing (Escape, or the control that
@ -426,7 +426,11 @@ export function Table<T>({
if (openFilterKey !== null) {
lastOpenKey.current = openFilterKey;
} else if (lastOpenKey.current !== null) {
restoreFocus(filterBtnRefs.current.get(lastOpenKey.current) ?? null);
restoreFocus(
filterBtnRefs.current.get(lastOpenKey.current) ?? null,
document.activeElement,
document.body,
);
lastOpenKey.current = null;
}
}, [openFilterKey]);