Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(ui): keep scrolling menu lists out of the tab order; fix flaky workflow library tests (#10315)

Lincoln Stein5921fd6e84c6
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowSwitcherLoading.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowSwitcherLoading.browser.test.tsx
index afe5bc8b06..4b427d56f4 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowSwitcherLoading.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/WorkflowSwitcherLoading.browser.test.tsx
@@ -102,6 +102,7 @@ describe('the workflow switcher while its scrolling list loads', () => {
const menu = () => document.querySelector<HTMLElement>('[role="menu"]');
const choices = () => [...document.querySelectorAll('[role="menuitemradio"]')].map((item) => item.textContent);
const themedList = () => menu()?.querySelector('[data-scope="scroll-area"]') ?? null;
+ const VIEWPORT = '[data-scope="scroll-area"][data-part="viewport"]';
const library = () => document.querySelector<HTMLElement>('[data-value="workflow-library"]')!;
const openMenu = async () => {
await act(() => userEvent.click(trigger()));
@@ -139,8 +140,24 @@ describe('the workflow switcher while its scrolling list loads', () => {
setWorkflowLibraryOpen(false);
await openMenu();
const before = library().getBoundingClientRect().top;
+ // Zag makes the viewport a tab stop until it measures its scrollbars, which can be between two polls; record the
+ // viewport's tabindex as it is inserted instead.
+ const insertedViewportTabIndexes: (string | null)[] = [];
+ const insertions = new MutationObserver((records) => {
+ for (const node of records.flatMap((record) => [...record.addedNodes])) {
+ if (node instanceof Element) {
+ const viewport = node.matches(VIEWPORT) ? node : node.querySelector(VIEWPORT);
+ if (viewport) {
+ insertedViewportTabIndexes.push(viewport.getAttribute('tabindex'));
+ }
+ }
+ }
+ });
+ insertions.observe(menu()!, { childList: true, subtree: true });
+ onTestFinished(() => insertions.disconnect());
await act(() => scrollableChunk.release());
await vi.waitFor(() => expect(themedList()).not.toBeNull(), { timeout: 8000 });
+ expect(insertedViewportTabIndexes).toEqual([null]);
expect(library().getBoundingClientRect().top).toBe(before);
expect(await auditAccessibility(menu()!)).toEqual([]);
expect(menu()!.contains(document.activeElement)).toBe(true);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryBrowse.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryBrowse.browser.test.tsx
index 3631307d2f..3bbc6d613f 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryBrowse.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryBrowse.browser.test.tsx
@@ -9,6 +9,7 @@ import { invalidateWorkflowLibraryCache } from '@features/workflow/data/libraryC
import { WorkflowUiProvider, WorkflowGraphPreviewProvider } from '@features/workflow/ui/WorkflowUiContext';
import { setWorkflowLibraryTab } from '@features/workflow/ui/workflowUiStore';
import { createProjectGraph } from '@features/workflow/utility';
+import { settleAnimations } from '@platform/browser/settleAnimations.testing';
import { accountLifecycle } from '@platform/state/accountLifecycle';
import { ApiError } from '@platform/transport/http';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
@@ -263,6 +264,9 @@ const open = async () => {
);
});
await waitFor(() => expect(card(0) ?? listRow(0)).not.toBeNull());
+ // The dialog opens scaled; geometry read before its animation ends is shrunken, and a slow runner can outlast a
+ // fixed settle.
+ await act(() => settleAnimations(document.querySelector('[data-scope="dialog"][data-part="content"]')!));
};
let activeDeepScroll: { abort: AbortController; done: Promise<void> } | null = null;
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
index 63752ed7f9..fe2267bc4e 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
@@ -1945,7 +1945,10 @@ describe('WorkflowLibraryDialog', () => {
expectUnclipped(close);
await act(() => userEvent.keyboard('{Enter}'));
expect(onOpenChange).toHaveBeenCalledWith(false);
- }
+ },
+ // A thousand-card grid and up to a hundred sequential keystrokes: 2–6 s on CI, with rare starved runs past the
+ // default 15 s. A timed-out case can keep running into the next one and fail it too.
+ 30000
);
it('keeps keyboard focus mounted across virtual row boundaries', async () => {
diff --git a/invokeai/frontend/webv2/src/platform/ui/ScrollableMenuContent.tsx b/invokeai/frontend/webv2/src/platform/ui/ScrollableMenuContent.tsx
index 6cf871362f..5e07a1ec23 100644
--- a/invokeai/frontend/webv2/src/platform/ui/ScrollableMenuContent.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/ScrollableMenuContent.tsx
@@ -10,10 +10,7 @@ import { Scrollable } from './Scrollable';
* highlight is skipped (the item under the pointer is already in view), as Zag does, so hovering an edge row does not
* nudge the list.
*/
-const followHighlightedItem = (viewport: HTMLDivElement | null) => {
- if (!viewport) {
- return;
- }
+const followHighlightedItem = (viewport: HTMLDivElement) => {
const observer = new MutationObserver((records) => {
for (const record of records) {
const item = record.target;
@@ -26,9 +23,34 @@ const followHighlightedItem = (viewport: HTMLDivElement | null) => {
return () => observer.disconnect();
};
+/**
+ * Keeps the viewport out of the tab order: the menu owns keyboard navigation, and a menu may not contain a focusable
+ * element, even at tabindex -1. Zag sets tabindex 0 until it first measures its scrollbars (and whenever both axes
+ * overflow), and an undefined prop cannot override it, so the attribute is removed on attach, before first paint, and
+ * whenever Zag sets it again.
+ */
+const keepOutOfTabOrder = (viewport: HTMLDivElement) => {
+ viewport.removeAttribute('tabindex');
+ const observer = new MutationObserver(() => viewport.removeAttribute('tabindex'));
+ observer.observe(viewport, { attributeFilter: ['tabindex'] });
+ return () => observer.disconnect();
+};
+
+const attachMenuViewport = (viewport: HTMLDivElement | null) => {
+ if (!viewport) {
+ return;
+ }
+ const stopKeepingOutOfTabOrder = keepOutOfTabOrder(viewport);
+ const stopFollowingHighlight = followHighlightedItem(viewport);
+ return () => {
+ stopKeepingOutOfTabOrder();
+ stopFollowingHighlight();
+ };
+};
+
/** A menu's scrolling list, in content laid out with `SCROLLABLE_MENU_CONTENT_PROPS`, above any rows that stay in view. */
export const ScrollableMenuList = ({ children }: { children: ReactNode }) => (
- <Scrollable minH="0" viewportRef={followHighlightedItem}>
+ <Scrollable minH="0" viewportRef={attachMenuViewport}>
{children}
</Scrollable>
);