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: make toast text selectable (#6423)

Michael Han88b1d6d4967f
diff --git a/studio/frontend/src/components/ui/sonner.tsx b/studio/frontend/src/components/ui/sonner.tsx
index faaa075fa27..33c2b772620 100644
--- a/studio/frontend/src/components/ui/sonner.tsx
+++ b/studio/frontend/src/components/ui/sonner.tsx
@@ -12,73 +12,100 @@ import { Spinner } from "@/components/ui/spinner";
import { useTheme } from "next-themes";
import { Toaster as Sonner, type ToasterProps } from "sonner";
+// Make toast text selectable. Sonner's onPointerDown calls setPointerCapture(),
+// which steals the drag and blocks text selection. dismissible:false would stop
+// it but also kills the close button. So we swallow pointerdown on toast text
+// (never on its buttons) before sonner sees it.
+const handleToastPointerDownCapture = (
+ event: React.PointerEvent<HTMLDivElement>,
+) => {
+ // closest() lives on Element, so this also covers SVG icon targets; guard
+ // against non-Element targets defensively.
+ const target = event.target as Element | null;
+ if (typeof target?.closest !== "function") return;
+ if (!target.closest("[data-sonner-toast]")) return;
+ if (
+ target.closest("button,[data-button],[data-close-button],[data-cancel]")
+ ) {
+ return;
+ }
+ event.stopPropagation();
+};
+
const Toaster = ({ ...props }: ToasterProps) => {
// Use resolvedTheme so sonner's data-sonner-theme always matches the class
// next-themes puts on <html>; sonner-side "system" resolution can drift.
const { resolvedTheme } = useTheme();
return (
- <Sonner
- theme={(resolvedTheme as ToasterProps["theme"]) ?? "light"}
- className="toaster group"
- duration={5000}
- icons={{
- success: (
- <HugeiconsIcon
- icon={CheckmarkCircle02Icon}
- strokeWidth={2}
- className="size-4"
- />
- ),
- info: (
- <HugeiconsIcon
- icon={InformationCircleIcon}
- strokeWidth={2}
- className="size-4"
- />
- ),
- warning: (
- <HugeiconsIcon
- icon={Alert02Icon}
- strokeWidth={2}
- className="size-4"
- />
- ),
- error: (
- <HugeiconsIcon
- icon={MultiplicationSignCircleIcon}
- strokeWidth={2}
- className="size-4"
- />
- ),
- // App-wide arc spinner so loading toasts match the "Downloading model" toast.
- loading: <Spinner className="size-4 text-muted-foreground" />,
- }}
- style={
- {
- "--normal-bg": "var(--popover)",
- "--normal-text": "var(--popover-foreground)",
- // No border line; elevation comes from the composer's drop shadow.
- "--normal-border": "transparent",
- "--border-radius": "var(--radius)",
- // Pin the close button inside the toast's top-right corner.
- // Sonner defaults to the left/outside edge, so keep the horizontal
- // override here and the top offset in index.css.
- "--toast-close-button-start": "unset",
- "--toast-close-button-end": "8px",
- "--toast-close-button-transform": "none",
- } as React.CSSProperties
- }
- // No swipe gestures; keeps toast text selectable.
- swipeDirections={[]}
- toastOptions={{
- classNames: {
- toast: "cn-toast",
- description: "!text-muted-foreground",
- },
- }}
- {...props}
- />
+ // display:contents adds no box; only carries the selection-fix handler.
+ // biome-ignore lint/a11y/noStaticElementInteractions: capture-only guard, not interactive
+ <div
+ style={{ display: "contents" }}
+ onPointerDownCapture={handleToastPointerDownCapture}
+ >
+ <Sonner
+ theme={(resolvedTheme as ToasterProps["theme"]) ?? "light"}
+ className="toaster group"
+ duration={5000}
+ icons={{
+ success: (
+ <HugeiconsIcon
+ icon={CheckmarkCircle02Icon}
+ strokeWidth={2}
+ className="size-4"
+ />
+ ),
+ info: (
+ <HugeiconsIcon
+ icon={InformationCircleIcon}
+ strokeWidth={2}
+ className="size-4"
+ />
+ ),
+ warning: (
+ <HugeiconsIcon
+ icon={Alert02Icon}
+ strokeWidth={2}
+ className="size-4"
+ />
+ ),
+ error: (
+ <HugeiconsIcon
+ icon={MultiplicationSignCircleIcon}
+ strokeWidth={2}
+ className="size-4"
+ />
+ ),
+ // App-wide arc spinner so loading toasts match the "Downloading model" toast.
+ loading: <Spinner className="size-4 text-muted-foreground" />,
+ }}
+ style={
+ {
+ "--normal-bg": "var(--popover)",
+ "--normal-text": "var(--popover-foreground)",
+ // No border line; elevation comes from the composer's drop shadow.
+ "--normal-border": "transparent",
+ "--border-radius": "var(--radius)",
+ // Pin the close button inside the toast's top-right corner.
+ // Sonner defaults to the left/outside edge, so keep the horizontal
+ // override here and the top offset in index.css.
+ "--toast-close-button-start": "unset",
+ "--toast-close-button-end": "8px",
+ "--toast-close-button-transform": "none",
+ } as React.CSSProperties
+ }
+ // No swipe gestures; text selection handled by the wrapper above.
+ swipeDirections={[]}
+ toastOptions={{
+ classNames: {
+ toast: "cn-toast",
+ description: "!text-muted-foreground",
+ },
+ }}
+ {...props}
+ />
+ </div>
);
};