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:
parent
d4f58b3667
commit
9338496e24
1 changed files with 107 additions and 10 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue