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(layers): quick menu icons select again

Josh Corbett39a1b758a63c
diff --git a/invokeai/frontend/webv2/src/platform/ui/Menu.tsx b/invokeai/frontend/webv2/src/platform/ui/Menu.tsx
index f4df839c1c..b578b8f8ab 100644
--- a/invokeai/frontend/webv2/src/platform/ui/Menu.tsx
+++ b/invokeai/frontend/webv2/src/platform/ui/Menu.tsx
@@ -1,8 +1,9 @@
import type { LucideIcon } from 'lucide-react';
import type { ComponentProps } from 'react';
-import { HStack, Icon, Kbd, Menu, Text, useMenuContext } from '@chakra-ui/react';
+import { Box, HStack, Icon, Kbd, Menu, Text, useMenuContext } from '@chakra-ui/react';
+import { Tooltip } from './Tooltip';
import { useRegisterWidgetOverlay } from './widgetOverlays';
type MenuContentProps = ComponentProps<typeof Menu.Content>;
@@ -69,3 +70,47 @@ export const MenuActionItem = ({
</HStack>
</Menu.Item>
);
+
+const ICON_ITEM_TOOLTIP_CONTENT_PROPS = { fontSize: '2xs' } as const;
+const ICON_ITEM_TOOLTIP_POSITIONING_PROPS = { placement: 'top' } as const;
+
+export interface MenuIconItemProps {
+ value: string;
+ /** The accessible name; also the hover tooltip, since the item shows only its icon. */
+ label: string;
+ icon: LucideIcon;
+ /** Lucide icons are stroke-only, so `'currentColor'` is how an on state reads. */
+ iconFill?: string;
+ tone?: 'danger';
+ disabled?: boolean;
+ onSelect: () => void;
+}
+
+/**
+ * An icon-only item for a menu's quick row. The tooltip wraps the icon, never
+ * the item: a tooltip trigger merged onto the item replaces the id zag selects
+ * by, so clicks and Enter would close the menu without firing `onSelect`.
+ */
+export const MenuIconItem = ({ disabled, icon, iconFill, label, onSelect, tone, value }: MenuIconItemProps) => (
+ <Menu.Item
+ aria-label={label}
+ data-danger={tone === 'danger' ? '' : undefined}
+ disabled={disabled}
+ flex="1"
+ justifyContent="center"
+ value={value}
+ onSelect={onSelect}
+ >
+ <Tooltip
+ showArrow
+ content={label}
+ contentProps={ICON_ITEM_TOOLTIP_CONTENT_PROPS}
+ openDelay={300}
+ positioning={ICON_ITEM_TOOLTIP_POSITIONING_PROPS}
+ >
+ <Box alignItems="center" display="flex" h="full" justifyContent="center" w="full">
+ <Icon as={icon} boxSize="4" color={tone === 'danger' ? undefined : 'fg'} fill={iconFill ?? 'none'} />
+ </Box>
+ </Tooltip>
+ </Menu.Item>
+);
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
index e07f2b62d8..060fa1561a 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
@@ -77,6 +77,14 @@ const interact = (action: () => void): Promise<void> =>
});
});
+/** Quick icon items select through zag, which needs the item highlighted by a hover before the click. */
+const pickQuickItem = async (label: string): Promise<void> => {
+ const target = document.querySelector<HTMLElement>(`[aria-label="${label}"]`);
+ expect(target).not.toBeNull();
+ await interact(() => target!.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, pointerType: 'mouse' })));
+ await interact(() => target!.click());
+};
+
const getMenuItem = (label: string): HTMLElement => {
const item = Array.from(document.querySelectorAll<HTMLElement>('[role="menuitem"]')).find(
(candidate) => candidate.textContent?.trim() === label
@@ -344,15 +352,21 @@ describe('ImageContextMenu mixed-media action visibility', () => {
y: 20,
});
- const openInNewTab = document.querySelector<HTMLButtonElement>('[aria-label="Open in new tab"]');
- const openInPreview = document.querySelector<HTMLButtonElement>('[aria-label="Open in preview"]');
- expect(openInNewTab).not.toBeNull();
- expect(openInPreview).not.toBeNull();
-
- await interact(() => {
- openInNewTab?.click();
- openInPreview?.click();
- });
+ const target = {
+ itemRefs: [
+ { kind: 'video' as const, name: primaryVideo.name },
+ { kind: 'video' as const, name: secondaryVideo.name },
+ ],
+ items: [primaryVideo, secondaryVideo],
+ x: 20,
+ y: 20,
+ };
+ // Selecting closes the menu, so each quick item gets its own open.
+ await pickQuickItem('Open in new tab');
+ await interact(() => root?.unmount());
+ host?.remove();
+ await renderItemMenu(actions, target);
+ await pickQuickItem('Open in preview');
expect(actions.openItemInNewTab).toHaveBeenCalledWith(primaryVideo);
expect(actions.openItemInPreview).toHaveBeenCalledWith(primaryVideo);
@@ -382,15 +396,11 @@ describe('ImageContextMenu mixed-media action visibility', () => {
expect(document.body.textContent).toContain('Change Board');
expect(document.body.textContent).toContain('Delete Selection');
expect(document.body.textContent).not.toContain('widgets.canvas.import.newFromImage');
- const openInNewTab = document.querySelector<HTMLButtonElement>('[aria-label="Open in new tab"]');
- const openInPreview = document.querySelector<HTMLButtonElement>('[aria-label="Open in preview"]');
- expect(openInNewTab).not.toBeNull();
- expect(openInPreview).not.toBeNull();
-
- await interact(() => {
- openInNewTab?.click();
- openInPreview?.click();
- });
+ await pickQuickItem('Open in new tab');
+ await interact(() => root?.unmount());
+ host?.remove();
+ await renderItemMenu(actions, { itemRefs: refs, items: [loadedImage], x: 20, y: 20 });
+ await pickQuickItem('Open in preview');
expect(actions.openItemInNewTab).toHaveBeenCalledWith(loadedImage);
expect(actions.openItemInPreview).toHaveBeenCalledWith(loadedImage);
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
index d1b20c7577..9a44965466 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx
@@ -11,7 +11,7 @@ import {
toGalleryItemKey,
} from '@features/gallery';
import { createVideoSourceClip } from '@features/video';
-import { MenuContent, Tooltip } from '@platform/ui';
+import { MenuContent, MenuIconItem } from '@platform/ui';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';
import { useWorkbenchCommands } from '@workbench/WorkbenchContext';
@@ -76,8 +76,6 @@ const MENU_CONTENT_PROPS = {
overflow: 'hidden',
} as const;
const MENU_POSITIONING_PROPS = { placement: 'right-start' } as const;
-const QUICK_MENU_TOOLTIP_CONTENT_PROPS = { fontSize: '2xs' } as const;
-const QUICK_MENU_TOOLTIP_POSITIONING_PROPS = { placement: 'top' } as const;
const isUsableGalleryImage = (value: unknown): value is GalleryImage =>
Boolean(value) &&
@@ -400,25 +398,25 @@ const SingleItemMenuItems = ({
return (
<>
<HStack gap="1">
- <QuickMenuItem
+ <MenuIconItem
icon={ExternalLinkIcon}
label="Open in new tab"
value="open-in-new-tab"
- onClick={handleOpenInNewTab}
+ onSelect={handleOpenInNewTab}
/>
- <QuickMenuItem
+ <MenuIconItem
icon={DownloadIcon}
label={`Download ${mediaLabel}`}
value="download-item"
- onClick={handleDownload}
+ onSelect={handleDownload}
/>
- <QuickMenuItem icon={EyeIcon} label="Open in preview" value="open-in-preview" onClick={handleOpenPreview} />
- <QuickMenuItem
+ <MenuIconItem icon={EyeIcon} label="Open in preview" value="open-in-preview" onSelect={handleOpenPreview} />
+ <MenuIconItem
icon={StarIcon}
iconFill={item.starred ? 'currentColor' : 'none'}
label={`${item.starred ? 'Unstar' : 'Star'} ${mediaLabel}`}
value="toggle-starred"
- onClick={handleToggleStarred}
+ onSelect={handleToggleStarred}
/>
</HStack>
<Menu.Separator borderColor="border.subtle" />
@@ -532,17 +530,17 @@ const BulkItemMenuItems = ({
</Text>
<Menu.Separator borderColor="border.subtle" />
<HStack gap="1">
- <QuickMenuItem
+ <MenuIconItem
icon={ExternalLinkIcon}
label="Open in new tab"
value="open-primary-in-new-tab"
- onClick={handleOpenInNewTab}
+ onSelect={handleOpenInNewTab}
/>
- <QuickMenuItem
+ <MenuIconItem
icon={EyeIcon}
label="Open in preview"
value="open-primary-in-preview"
- onClick={handleOpenPreview}
+ onSelect={handleOpenPreview}
/>
</HStack>
<Menu.Separator borderColor="border.subtle" />
@@ -851,26 +849,26 @@ const OpenInNewTabQuickMenuItem = ({ image }: { image: GalleryImage }) => {
const handleClick = useCallback(() => window.open(image.imageUrl, '_blank', 'noopener'), [image.imageUrl]);
return (
- <QuickMenuItem icon={ExternalLinkIcon} label="Open in new tab" value="open-in-new-tab" onClick={handleClick} />
+ <MenuIconItem icon={ExternalLinkIcon} label="Open in new tab" value="open-in-new-tab" onSelect={handleClick} />
);
};
const CopyQuickMenuItem = ({ actions, image }: { actions: ImageActions; image: GalleryImage }) => {
const handleClick = useCallback(() => void actions.copyImage(image), [actions, image]);
- return <QuickMenuItem icon={CopyIcon} label="Copy to clipboard" value="copy-to-clipboard" onClick={handleClick} />;
+ return <MenuIconItem icon={CopyIcon} label="Copy to clipboard" value="copy-to-clipboard" onSelect={handleClick} />;
};
const DownloadQuickMenuItem = ({ actions, image }: { actions: ImageActions; image: GalleryImage }) => {
const handleClick = useCallback(() => void actions.downloadImage(image), [actions, image]);
- return <QuickMenuItem icon={DownloadIcon} label="Download image" value="download-image" onClick={handleClick} />;
+ return <MenuIconItem icon={DownloadIcon} label="Download image" value="download-image" onSelect={handleClick} />;
};
const OpenPreviewQuickMenuItem = ({ actions, image }: { actions: ImageActions; image: GalleryImage }) => {
const handleClick = useCallback(() => actions.openImageInPreview(image), [actions, image]);
- return <QuickMenuItem icon={EyeIcon} label="Open in preview" value="open-in-preview" onClick={handleClick} />;
+ return <MenuIconItem icon={EyeIcon} label="Open in preview" value="open-in-preview" onSelect={handleClick} />;
};
const ToggleStarQuickMenuItem = ({ actions, image }: { actions: ImageActions; image: GalleryImage }) => {
@@ -880,12 +878,12 @@ const ToggleStarQuickMenuItem = ({ actions, image }: { actions: ImageActions; im
);
return (
- <QuickMenuItem
+ <MenuIconItem
icon={StarIcon}
iconFill={image.starred ? 'currentColor' : 'none'}
label={image.starred ? 'Unstar image' : 'Star image'}
value="toggle-starred"
- onClick={handleClick}
+ onSelect={handleClick}
/>
);
};
@@ -1095,33 +1093,6 @@ const ContextSubMenu = ({
</Menu.Root>
);
-const QuickMenuItem = ({
- icon,
- iconFill,
- label,
- value,
- onClick,
-}: {
- icon: LucideIcon;
- /** Lucide icons are stroke-only, so `'currentColor'` is how an on state reads. */
- iconFill?: string;
- label: string;
- value: string;
- onClick: () => void;
-}) => (
- <Tooltip
- showArrow
- content={label}
- contentProps={QUICK_MENU_TOOLTIP_CONTENT_PROPS}
- openDelay={300}
- positioning={QUICK_MENU_TOOLTIP_POSITIONING_PROPS}
- >
- <Menu.Item aria-label={label} flex="1" justifyContent="center" value={value} onClick={onClick}>
- <Icon as={icon} boxSize="4" color="fg" fill={iconFill} />
- </Menu.Item>
- </Tooltip>
-);
-
const ContextMenuItem = ({
disabled,
icon,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
index 117be73dc8..e36cc2a775 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
@@ -18,7 +18,7 @@ import type { ComponentProps, Dispatch, ReactNode } from 'react';
import { HStack, Icon, Menu, Portal, Text } from '@chakra-ui/react';
import { galleryTransfers } from '@features/gallery';
import { useModelsSelector } from '@features/models';
-import { IconButton, MenuActionItem, MenuContent, RenameDialog, Tooltip } from '@platform/ui';
+import { IconButton, MenuActionItem, MenuContent, MenuIconItem, RenameDialog, Tooltip } from '@platform/ui';
import {
canMergeSelectedRasters,
getDocumentIndex,
@@ -86,7 +86,7 @@ import {
getLayerContextMenuLayout,
getLayerContextMenuRenderEntries,
} from './layerContextMenuLayout';
-import { copyBlobToClipboard, saveLayerToAssets } from './layerExportActions';
+import { copyLayerToClipboard, saveLayerToAssets } from './layerExportActions';
import { canGroupSelection, groupLayers } from './layerGroupCommands';
import { resolveMenuTargetForRender } from './layerMenuState';
import {
@@ -587,11 +587,10 @@ const LayerMenu = ({
if (!engine) {
throw makeStatusError('not-ready');
}
- const result = await engine.exports.exportBakedLayerBlob(layer.id, { includeDisabled: true });
- if (result.status !== 'ok') {
- throw makeStatusError(result.status);
+ const status = await copyLayerToClipboard(layer.id, { exportLayer: engine.exports.exportBakedLayerBlob });
+ if (status !== 'ok') {
+ throw makeStatusError(status);
}
- await copyBlobToClipboard(result.blob);
}, [engine, layer.id, makeStatusError]);
const handleCropToBbox = useCallback(async () => {
@@ -1237,7 +1236,7 @@ const LayerMenuIconActionItem = ({
const onSelect = useCallback(() => runAction(action), [action, runAction]);
return (
- <LayerMenuIconItem
+ <MenuIconItem
disabled={action.isDisabled}
icon={action.icon}
label={t(action.labelKey, { count: action.labelCount, defaultValue: action.defaultLabel })}
@@ -1304,39 +1303,3 @@ const LayerMenuItem = ({
onSelect={onSelect}
/>
);
-
-const LayerMenuIconItem = ({
- disabled,
- icon,
- label,
- onSelect,
- tone,
- value,
-}: {
- disabled?: boolean;
- icon: LucideIcon;
- label: string;
- onSelect: () => void;
- tone?: 'danger';
- value: string;
-}) => (
- <Tooltip
- showArrow
- content={label}
- contentProps={QUICK_MENU_TOOLTIP_CONTENT_PROPS}
- openDelay={300}
- positioning={QUICK_MENU_TOOLTIP_POSITIONING_PROPS}
- >
- <Menu.Item
- aria-label={label}
- data-danger={tone === 'danger' ? '' : undefined}
- disabled={disabled}
- flex="1"
- justifyContent="center"
- value={value}
- onSelect={onSelect}
- >
- <Icon as={icon} boxSize="4" color={tone === 'danger' ? undefined : 'fg'} />
- </Menu.Item>
- </Tooltip>
-);