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(webv2): ignore touch presses on preset tabs

joshistoastd74c987ccf09
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
index 5a6e07e229..9cca4da1a5 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
@@ -321,7 +321,7 @@ const PresetTab = ({
// a future sensor swap does not silently lose its activator.
(listeners as { onPointerDown?: (value: unknown) => void } | undefined)?.onPointerDown?.(event);
- if (event.button === 0 && !isActive) {
+ if (event.button === 0 && event.pointerType !== 'touch' && !isActive) {
onRequest(preset.id);
}
},
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStripAck.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStripAck.browser.test.tsx
index eebdeae500..5f02b79741 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStripAck.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStripAck.browser.test.tsx
@@ -97,9 +97,9 @@ const presetTab = (id: string): HTMLElement => {
return tab;
};
-const press = (element: Element, button = 0): Promise<void> =>
+const press = (element: Element, button = 0, pointerType = 'mouse'): Promise<void> =>
act(async () => {
- element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button, cancelable: true }));
+ element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button, cancelable: true, pointerType }));
await Promise.resolve();
});
@@ -168,6 +168,24 @@ describe('LayoutPresetStrip acknowledgment', () => {
expect(activate).not.toHaveBeenCalled();
});
+ // The strip is horizontally scrollable and its tabs carry `touchAction:
+ // 'pan-x'`, so a finger landing on an inactive tab to begin a pan is a
+ // supported gesture, not a click. Activating on touch `pointerdown` would
+ // switch the layout before the pan even starts. Touch keeps activating on
+ // `click`, same as before this component acknowledged presses at all.
+ it('ignores a touch-pointer press', async () => {
+ const activate = vi.fn<ActivatePreset>(() => Promise.resolve('edit'));
+
+ await render({ activatePreset: activate, activePresetId: 'compose' });
+
+ await press(presetTab('edit'), 0, 'touch');
+ await nextFrame();
+
+ expect(activate).not.toHaveBeenCalled();
+ expect(presetTab('edit').getAttribute('aria-selected')).toBe('false');
+ expect(presetTab('compose').getAttribute('aria-selected')).toBe('true');
+ });
+
// `pointerdown` fires for the secondary button too, ahead of `contextmenu`.
// Switching on right-click would strip the menu of the "switch to this
// preset" item that is the whole reason to open it on an inactive tab.