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): open list row menus from any non-mouse activation

Josh Corbett1351403afc84
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
index 939bf68489..30db872df6 100644
--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConceptRow.browser.test.tsx
@@ -238,6 +238,15 @@ describe('ConceptRow', () => {
expect(onRemove).toHaveBeenCalledWith('lora-1');
});
+ it('does not open row actions on a pointer click', async () => {
+ const row = await render(makeLora());
+
+ await act(() => userEvent.click(row.querySelector<HTMLElement>('[data-list-primary]')!));
+
+ expect(document.querySelector('[role="menu"][data-state="open"]')).toBeNull();
+ expect(row.querySelector('[data-list-primary]')?.getAttribute('aria-expanded')).toBe('false');
+ });
+
it.each(['{Enter}', ' '])('opens row actions on %s and restores focus on Escape', async (key) => {
const row = await render(makeLora());
const primary = row.querySelector<HTMLElement>('[data-list-primary]')!;
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
index c2390ab81f..36c8345085 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/ListChrome.browser.test.tsx
@@ -237,6 +237,47 @@ describe('list dividers', () => {
expect(hairlines().map((line) => getComputedStyle(line).opacity)).toEqual(['1', '1']);
});
+ it('opens a menu-only row from keyboard, assistive-tech, and touch activation, but not a mouse click', async () => {
+ const onContextMenu = vi.fn();
+ await render(
+ <ListStack label="subjects">
+ <ListItem title="one" onContextMenu={onContextMenu} />
+ </ListStack>
+ );
+ const primary = host.querySelector<HTMLButtonElement>('[data-list-primary]')!;
+ const tap = (pointerType: string) => {
+ primary.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, pointerType }));
+ primary.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }));
+ };
+
+ await act(() => tap('mouse'));
+ expect(onContextMenu).not.toHaveBeenCalled();
+
+ // NVDA/JAWS in Firefox click with detail 1 and no pointer press.
+ await act(() => primary.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 })));
+ await act(() => tap('touch'));
+ await act(() => tap('pen'));
+ expect(onContextMenu).toHaveBeenCalledTimes(3);
+ });
+
+ it('points a row whose only interaction is its actions', async () => {
+ await render(
+ <ListStack dividers label="subjects">
+ <ListItem title="one" />
+ <ListItem actions={<button type="button">Install</button>} title="two" />
+ <ListItem title="three" />
+ </ListStack>
+ );
+ const row = host.querySelectorAll<HTMLElement>('[data-list-surface]')[1]!;
+ const background = getComputedStyle(row).backgroundColor;
+
+ await userEvent.hover(row);
+ // Still not a button itself: the install button is the row's only control.
+ expect(row.querySelector('[data-list-primary]')?.tagName).toBe('DIV');
+ await expect.poll(() => getComputedStyle(row).backgroundColor).not.toBe(background);
+ await expect.poll(() => hairlines().map((line) => getComputedStyle(line).opacity)).toEqual(['0', '0']);
+ });
+
it('hides the hairlines either side of a pointed row, stacked or virtualized', async () => {
const opacities = () =>
[...host.querySelectorAll<HTMLElement>('[data-list-divider]')].map((line) => getComputedStyle(line).opacity);
diff --git a/invokeai/frontend/webv2/src/platform/ui/list/ListItem.tsx b/invokeai/frontend/webv2/src/platform/ui/list/ListItem.tsx
index 88ab00bd3a..029ad68d4e 100644
--- a/invokeai/frontend/webv2/src/platform/ui/list/ListItem.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/list/ListItem.tsx
@@ -1,9 +1,9 @@
-import type { MouseEvent, ReactNode } from 'react';
+import type { MouseEvent, PointerEvent, ReactNode } from 'react';
import { Checkbox, chakra, useSlotRecipe } from '@chakra-ui/react';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { listItemSlotRecipe } from '@theme/recipes';
-import { useCallback, useMemo } from 'react';
+import { useCallback, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
export type ListDensity = 'compact' | 'regular' | 'comfortable' | 'snug';
@@ -66,7 +66,10 @@ export interface ListItemProps {
onIntent?: () => void;
/** Renders the leading checkbox. */
onCheckedChange?: (checked: boolean) => void;
- /** Without onPress, activating the primary button also opens this menu. */
+ /**
+ * Without onPress, activating the primary button also opens this menu, except from a mouse click, where
+ * right-click is the path; keyboard, assistive-technology, touch, and pen activation all open it.
+ */
onContextMenu?: (anchor: ListContextMenuAnchor) => void;
}
@@ -109,6 +112,9 @@ export const ListItem = ({
const styles = useMemo(() => recipe({ active: tone, density }), [density, recipe, tone]);
// Inside a List every row is a keyboard stop; a standalone row is a button only when pressing it does something.
const isInteractive = onPress !== undefined || onContextMenu !== undefined || itemKey !== undefined;
+ // A row with actions is pointed like an interactive one, so its buttons read as belonging to it; only a row with
+ // nothing to act on stays static.
+ const isStatic = !isInteractive && (actions === undefined || actions === null);
const openContextMenu = useCallback(
(row: HTMLElement, point?: { x: number; y: number }) => {
@@ -163,14 +169,24 @@ export const ListItem = ({
(details: { checked: boolean | 'indeterminate' }) => onCheckedChange?.(details.checked === true),
[onCheckedChange]
);
+ // Detect a mouse press positively: screen readers synthesize clicks that look like pointer clicks (detail 1), and
+ // touch has no right-click, so only a click that a mouse pressed skips the menu.
+ const pressPointerType = useRef<string | null>(null);
+ const handlePointerDown = useCallback((event: PointerEvent<HTMLButtonElement>) => {
+ pressPointerType.current = event.pointerType;
+ }, []);
const handlePress = useCallback(
(event: MouseEvent<HTMLButtonElement>) => {
+ // Firefox marks screen-reader activation as a virtual input source even when it fires pointer events for it.
+ const isVirtualClick = (event.nativeEvent as { mozInputSource?: number }).mozInputSource === 0;
+ const isMouseClick = pressPointerType.current === 'mouse' && event.detail > 0 && !isVirtualClick;
+ pressPointerType.current = null;
if (isBusy) {
return;
}
if (onPress) {
onPress(event);
- } else if (event.currentTarget.parentElement) {
+ } else if (!isMouseClick && event.currentTarget.parentElement) {
openContextMenu(event.currentTarget.parentElement);
}
},
@@ -216,7 +232,7 @@ export const ListItem = ({
data-list-row={itemKey}
data-list-surface=""
data-menu-open={isMenuOpen || undefined}
- data-static={!isInteractive || undefined}
+ data-static={isStatic || undefined}
role={role}
onContextMenu={onContextMenu ? handleContextMenu : undefined}
>
@@ -247,6 +263,7 @@ export const ListItem = ({
type="button"
onClick={handlePress}
onFocus={onIntent}
+ onPointerDown={onPress ? undefined : handlePointerDown}
onPointerEnter={onIntent}
>
{content}