Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: open the tile's own menu on a right-click in the Images strip (#15276)

Debojyoti Banerjee12e8e47e4ffb
diff --git a/studio/frontend/src/components/gallery-item-menu.tsx b/studio/frontend/src/components/gallery-item-menu.tsx
index 0923623d230..d1c45e659e2 100644
--- a/studio/frontend/src/components/gallery-item-menu.tsx
+++ b/studio/frontend/src/components/gallery-item-menu.tsx
@@ -51,6 +51,8 @@ export function GalleryItemMenu({
variant = "toolbar",
noun,
active = true,
+ open: openProp,
+ onOpenChange,
className,
}: {
pinned: boolean;
@@ -71,17 +73,25 @@ export function GalleryItemMenu({
noun: MediaNoun;
/** False while the page is off-tab; forces the menu shut so a portalled popup cannot outlive it. */
active?: boolean;
+ /** Opens the menu from outside, e.g. a right-click on the tile it sits on. Uncontrolled when omitted. */
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
className?: string;
}) {
// Controlled like RecipePopover: DropdownMenuContent portals to body, so the inert page wrapper
// cannot contain it when the tab goes away.
const t = useT();
- const [open, setOpen] = useState(false);
+ const [ownOpen, setOwnOpen] = useState(false);
+ const open = openProp ?? ownOpen;
+ const setOpen = (next: boolean) => {
+ setOwnOpen(next);
+ onOpenChange?.(next);
+ };
const project = useProjectSubmenu({ noun, onAddToProject });
const closeProject = project.close;
useEffect(() => {
if (!active) {
- setOpen(false);
+ setOwnOpen(false);
closeProject();
}
}, [active, closeProject]);
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index e07ac1a609f..d3db0058b15 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -2501,6 +2501,10 @@ export function ImagesPage({
const viewerImage = viewerId ? (images.find((image) => image.id === viewerId) ?? null) : null;
const viewerSrc = viewerImage ? srcById[viewerImage.id] : undefined;
if (viewerId && (!active || !viewerImage)) setViewerId(null);
+ // The strip tile whose actions menu a right-click opened. A tile's <img> would otherwise get the
+ // webview's own image menu, whose Open in New Window and Copy Image cannot act on a blob: URL.
+ const [tileMenuId, setTileMenuId] = useState<string | null>(null);
+ if (tileMenuId && (!active || !images.some((image) => image.id === tileMenuId))) setTileMenuId(null);
// Pruning below must not revoke the image on screen.
const viewerIdRef = useRef<string | null>(null);
useEffect(() => {
@@ -7644,6 +7648,13 @@ export function ImagesPage({
key={image.id}
data-image-id={image.id}
{...stripReorder.tileProps(image.id)}
+ // Desktop only: a browser's own image menu works on these thumbnails, so keep it there.
+ // Portalled children (the New project dialog) bubble here too: leave their menu alone.
+ onContextMenu={(event) => {
+ if (!isTauri || !event.currentTarget.contains(event.target as Node)) return;
+ event.preventDefault();
+ setTileMenuId(image.id);
+ }}
className={cn(
"group relative size-16 shrink-0",
// Fade the tile being dragged.
@@ -7688,6 +7699,8 @@ export function ImagesPage({
variant="overlay"
noun="image"
active={active}
+ open={tileMenuId === image.id}
+ onOpenChange={(open) => setTileMenuId(open ? image.id : null)}
pinned={Boolean(image.pinned)}
archived={Boolean(image.archived)}
favorite={isFavorite(`image:${image.id}`)}
diff --git a/studio/frontend/tests/images-strip-context-menu.test.ts b/studio/frontend/tests/images-strip-context-menu.test.ts
new file mode 100644
index 00000000000..1af9c030fdd
--- /dev/null
+++ b/studio/frontend/tests/images-strip-context-menu.test.ts
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+test("a right-click on an Images strip tile opens the tile's actions menu", () => {
+ const page = readSrc("features/images/images-page.tsx");
+ const tile = page.slice(page.indexOf("data-image-id={image.id}"));
+ const handler = /onContextMenu=\{\(event\) => \{([^}]*)\}\}/.exec(tile)?.[1] ?? "";
+ // The desktop webview's own image menu cannot open or copy a blob: thumbnail, so it must not show there.
+ // A browser's menu works on them, so browsers keep it.
+ // React bubbles a portalled child's event (the New project dialog) through the tile: only the tile's own DOM counts.
+ assert.match(
+ handler,
+ /^\s*if \(!isTauri \|\| !event\.currentTarget\.contains\(event\.target as Node\)\) return;\s*event\.preventDefault\(\)/,
+ );
+ assert.match(handler, /setTileMenuId\(image\.id\)/);
+ assert.match(tile, /open=\{tileMenuId === image\.id\}/);
+ assert.match(tile, /onOpenChange=\{\(open\) => setTileMenuId\(open \? image\.id : null\)\}/);
+ // A tab switch or a deleted tile drops the request, so it cannot reopen later.
+ assert.match(page, /if \(tileMenuId && \(!active \|\| !images\.some\(/);
+});
+
+test("the gallery item menu can be opened from outside and still closes off-tab", () => {
+ const menu = readSrc("components/gallery-item-menu.tsx");
+ assert.match(menu, /const open = openProp \?\? ownOpen;/);
+ assert.match(menu, /onOpenChange\?\.\(next\)/);
+ assert.match(menu, /open=\{active && open\}/);
+});