Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(ui): keep plugin category menu inside the catalog dialog

rubenluetke10-beep2af4c5c56562
diff --git a/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx b/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
index 34b504d3b7..72d99b9960 100644
--- a/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/ui/combobox.test.tsx
@@ -144,6 +144,72 @@ describe("Combobox panel placement", () => {
expect(panel.style.top).toBe("");
expect(parseInt(panel.style.maxHeight, 10)).toBeGreaterThanOrEqual(160);
});
+
+ it("measures against a transformed dialog instead of the viewport, so the list sits under the trigger", async () => {
+ // PluginsDialog (and every centred Radix sheet) uses translate(-50%,-50%)
+ // plus overflow:hidden. Viewport coordinates inside that box paint the
+ // list far below the trigger; focusing it then scrolls the tab strip away.
+ vi.spyOn(window, "innerHeight", "get").mockReturnValue(900);
+ vi.spyOn(window, "innerWidth", "get").mockReturnValue(1200);
+ render(
+ <div
+ role="dialog"
+ data-testid="host-dialog"
+ style={{
+ position: "fixed",
+ transform: "translate(-50%, -50%)",
+ overflow: "hidden",
+ width: 800,
+ height: 780,
+ }}
+ >
+ <Combobox
+ value="alpha"
+ groups={GROUPS}
+ onChange={() => {}}
+ ariaLabel="Pick"
+ testId="trapped"
+ />
+ </div>,
+ );
+ const host = screen.getByTestId("host-dialog");
+ const trigger = screen.getByTestId("trapped");
+ vi.spyOn(host, "getBoundingClientRect").mockReturnValue({
+ top: 60,
+ bottom: 840,
+ left: 200,
+ right: 1000,
+ width: 800,
+ height: 780,
+ x: 200,
+ y: 60,
+ toJSON: () => ({}),
+ } as DOMRect);
+ Object.defineProperty(host, "clientLeft", { value: 0 });
+ Object.defineProperty(host, "clientTop", { value: 0 });
+ Object.defineProperty(host, "clientWidth", { value: 800 });
+ Object.defineProperty(host, "clientHeight", { value: 780 });
+ vi.spyOn(trigger, "getBoundingClientRect").mockReturnValue({
+ top: 220,
+ bottom: 248,
+ left: 240,
+ right: 400,
+ width: 160,
+ height: 28,
+ x: 240,
+ y: 220,
+ toJSON: () => ({}),
+ } as DOMRect);
+
+ fireEvent.click(trigger);
+ const panel = await screen.findByTestId("trapped-panel");
+ // trigger.bottom + 6 - host.top = 248 + 6 - 60 = 194, not the viewport 254.
+ expect(panel.style.top).toBe("194px");
+ expect(panel.style.left).toBe("40px");
+ expect(panel.className).toContain("absolute");
+ expect(panel.className).not.toMatch(/(?:^|\s)fixed(?:\s|$)/);
+ expect(host.scrollTop).toBe(0);
+ });
});
describe("Combobox inside a modal dialog", () => {
diff --git a/jarvis/ui/web/frontend/src/components/ui/combobox.tsx b/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
index 1322d302b0..ec3e8dac15 100644
--- a/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
+++ b/jarvis/ui/web/frontend/src/components/ui/combobox.tsx
@@ -37,6 +37,13 @@ import { cn } from "@/lib/utils";
* onto `body` paints on top of the dialog and receives no clicks — every
* option visible, none selectable. When the trigger lives in a dialog the
* panel lands inside that layer instead.
+ *
+ * Dialogs in this app are centred with `transform: translate(-50%, -50%)` and
+ * clip with `overflow: hidden`. A transform makes the dialog the containing
+ * block for `position: fixed`, so viewport coordinates would paint the list
+ * far below the trigger; focusing it then scrolls the clipped dialog and the
+ * tab strip disappears. Inside a positioned/transformed host the panel is
+ * `absolute` and measured in that host's box instead.
*/
export interface ComboboxOption {
@@ -116,6 +123,31 @@ function panelHost(trigger: HTMLElement | null): HTMLElement {
return trigger?.closest<HTMLElement>('[role="dialog"]') ?? document.body;
}
+function isRootHost(host: HTMLElement): boolean {
+ return host === document.body || host === document.documentElement;
+}
+
+/** Any dialog host is a containing block; `body` is the viewport. */
+function trapsPanel(host: HTMLElement): boolean {
+ return !isRootHost(host);
+}
+
+function hostBox(host: HTMLElement): {
+ left: number;
+ top: number;
+ right: number;
+ bottom: number;
+ width: number;
+ height: number;
+} {
+ const rect = host.getBoundingClientRect();
+ const left = rect.left + host.clientLeft;
+ const top = rect.top + host.clientTop;
+ const width = host.clientWidth || rect.width;
+ const height = host.clientHeight || rect.height;
+ return { left, top, width, height, right: left + width, bottom: top + height };
+}
+
function fold(value: string): string {
return value
.toLocaleLowerCase()
@@ -250,13 +282,23 @@ export function Combobox({
const measure = useCallback(() => {
const trigger = triggerRef.current;
if (!trigger) return;
+ const host = panelHost(trigger);
+ const trapped = trapsPanel(host);
+ const box = trapped
+ ? hostBox(host)
+ : {
+ left: 0,
+ top: 0,
+ right: window.innerWidth,
+ bottom: window.innerHeight,
+ width: window.innerWidth,
+ height: window.innerHeight,
+ };
const rect = trigger.getBoundingClientRect();
- const width = Math.min(
- Math.max(rect.width, MIN_PANEL_WIDTH),
- window.innerWidth - 2 * VIEWPORT_MARGIN,
- );
- const spaceBelow = window.innerHeight - rect.bottom - VIEWPORT_MARGIN;
- const spaceAbove = rect.top - VIEWPORT_MARGIN;
+ const maxWidth = Math.max(MIN_PANEL_WIDTH, box.width - 2 * VIEWPORT_MARGIN);
+ const width = Math.min(Math.max(rect.width, MIN_PANEL_WIDTH), maxWidth);
+ const spaceBelow = box.bottom - rect.bottom - VIEWPORT_MARGIN;
+ const spaceAbove = rect.top - box.top - VIEWPORT_MARGIN;
// Flip upwards only when below is genuinely too cramped AND above is
// roomier — a panel that jumps sides on a two-pixel scroll reads as a bug.
const flipUp = spaceBelow < 220 && spaceAbove > spaceBelow;
@@ -264,14 +306,24 @@ export function Combobox({
160,
Math.min(MAX_PANEL_HEIGHT, flipUp ? spaceAbove : spaceBelow),
);
- const left = Math.min(
- Math.max(VIEWPORT_MARGIN, rect.left),
- Math.max(VIEWPORT_MARGIN, window.innerWidth - width - VIEWPORT_MARGIN),
+ const leftViewport = Math.min(
+ Math.max(box.left + VIEWPORT_MARGIN, rect.left),
+ Math.max(box.left + VIEWPORT_MARGIN, box.right - width - VIEWPORT_MARGIN),
);
setPosition(
flipUp
- ? { left, bottom: window.innerHeight - rect.top + 6, width, maxHeight }
- : { left, top: rect.bottom + 6, width, maxHeight },
+ ? {
+ left: leftViewport - box.left,
+ bottom: box.bottom - rect.top + 6,
+ width,
+ maxHeight,
+ }
+ : {
+ left: leftViewport - box.left,
+ top: rect.bottom + 6 - box.top,
+ width,
+ maxHeight,
+ },
);
}, []);
@@ -296,7 +348,9 @@ export function Combobox({
// be. A callback ref fires exactly when the node appears, and once per open,
// so repositioning on scroll does not yank focus back.
const focusOnMount = useCallback((node: HTMLElement | null) => {
- node?.focus();
+ // preventScroll: a mis-measured panel inside overflow:hidden would
+ // otherwise yank the dialog's scrollTop and hide the tab strip.
+ node?.focus({ preventScroll: true });
}, []);
const attachSearch = useCallback(
@@ -408,6 +462,7 @@ export function Combobox({
const triggerLabel = selected?.label ?? fallbackLabel ?? value;
const activeOption = enabled[activeIndex];
+ const trapped = trapsPanel(panelHost(triggerRef.current));
return (
<>
@@ -478,7 +533,12 @@ export function Combobox({
// so the list has a predictable ground whatever it covers.
// pointer-events-auto: a modal dialog sets none on body, and this
// panel must still take the click even if it fell back to body.
- className="pointer-events-auto fixed z-[70] flex flex-col overflow-hidden rounded-lg border border-border-strong bg-popover shadow-float"
+ // absolute inside a transformed/fixed dialog: that dialog is the
+ // containing block, and the measured left/top are in its box.
+ className={cn(
+ "pointer-events-auto z-[70] flex flex-col overflow-hidden rounded-lg border border-border-strong bg-popover shadow-float",
+ trapped ? "absolute" : "fixed",
+ )}
>
{searchable && (
<div className="flex items-center gap-2 border-b border-border px-3 py-2">
diff --git a/jarvis/ui/web/frontend/src/views/PluginsDialog.test.tsx b/jarvis/ui/web/frontend/src/views/PluginsDialog.test.tsx
index 4f34634bf8..79687bd84d 100644
--- a/jarvis/ui/web/frontend/src/views/PluginsDialog.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/PluginsDialog.test.tsx
@@ -44,6 +44,19 @@ it("groups all plugins in product category order and keeps installed filtering f
expect(screen.queryByRole("button", { name: "GitHub" })).toBeNull();
});
+it("opens the category list without dismissing the tab strip", async () => {
+ setup();
+ await screen.findByRole("button", { name: "Gmail" });
+ const dialog = screen.getByTestId("plugin-catalog-dialog");
+ fireEvent.click(screen.getByTestId("plugin-window-category"));
+ expect(await screen.findByRole("option", { name: "All categories" })).toBeDefined();
+ expect(screen.getByRole("option", { name: "Developer" })).toBeDefined();
+ expect(screen.getByRole("option", { name: "Calendar & Mail" })).toBeDefined();
+ expect(screen.getByRole("tab", { name: "Plugins" })).toBeDefined();
+ expect(screen.getByRole("tab", { name: "Skills" })).toBeDefined();
+ expect(dialog.scrollTop).toBe(0);
+});
+
it("closes credential setup with Escape without closing the plugin window", async () => {
const { onClose } = setup();
const github = await screen.findByRole("button", { name: "GitHub" });
diff --git a/jarvis/ui/web/frontend/src/views/PluginsDialog.tsx b/jarvis/ui/web/frontend/src/views/PluginsDialog.tsx
index 5ecbac95d9..67c1818512 100644
--- a/jarvis/ui/web/frontend/src/views/PluginsDialog.tsx
+++ b/jarvis/ui/web/frontend/src/views/PluginsDialog.tsx
@@ -2,6 +2,7 @@ import * as Dialog from "@radix-ui/react-dialog";
import { useRef } from "react";
import { X } from "lucide-react";
import { useT } from "@/i18n";
+import { isComboboxPanelEvent } from "@/components/ui/combobox";
import { PluginsView } from "@/views/PluginsView";
import { SkillsView } from "@/views/SkillsView";
import { McpsView } from "@/views/McpsView";
@@ -40,8 +41,20 @@ export function PluginsDialog({ onClose, area = "plugins", onAreaChange }: {
target.focus({ preventScroll: true });
if (needsTabIndex) target.removeAttribute("tabindex");
}}
+ onPointerDownOutside={(event) => {
+ if (isComboboxPanelEvent(event) || content.current?.querySelector('[aria-modal="true"]')) {
+ event.preventDefault();
+ }
+ }}
+ onFocusOutside={(event) => {
+ if (isComboboxPanelEvent(event) || content.current?.querySelector('[aria-modal="true"]')) {
+ event.preventDefault();
+ }
+ }}
onInteractOutside={(event) => {
- if (content.current?.querySelector('[aria-modal="true"]')) event.preventDefault();
+ if (isComboboxPanelEvent(event) || content.current?.querySelector('[aria-modal="true"]')) {
+ event.preventDefault();
+ }
}}
onEscapeKeyDown={(event) => {
// The existing credential dialogs own Escape while they are open.
diff --git a/jarvis/ui/web/frontend/src/views/PluginsView.tsx b/jarvis/ui/web/frontend/src/views/PluginsView.tsx
index bf51fb017b..d0b40cd19d 100644
--- a/jarvis/ui/web/frontend/src/views/PluginsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/PluginsView.tsx
@@ -1327,6 +1327,7 @@ function PluginWindowCatalog({
</div>
<BrandedSelect value={category} onValueChange={onCategory}
ariaLabel={translate("plugins_view.col_category")}
+ testId="plugin-window-category"
className="h-8 w-auto max-w-full rounded-full bg-secondary px-3 text-xs"
options={[{ value: "all", label: translate("plugins_view.all_categories") },
...[...categories].sort((a, b) => WINDOW_CATEGORY_ORDER.indexOf(a) - WINDOW_CATEGORY_ORDER.indexOf(b)).map((name) => ({ value: name, label: name }))]} />