Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(ui): keep nested dropdowns inside narrow viewports (#17776)

Nikita Kabardin344db624d5fd
diff --git a/web/src/components/design-system/DropdownMenu/DropdownMenu.stories.tsx b/web/src/components/design-system/DropdownMenu/DropdownMenu.stories.tsx
index 5a8fe761c2..1ee01fb1fe 100644
--- a/web/src/components/design-system/DropdownMenu/DropdownMenu.stories.tsx
+++ b/web/src/components/design-system/DropdownMenu/DropdownMenu.stories.tsx
@@ -345,3 +345,81 @@ export const TestCheckboxAndSubmenu = meta.story({
await expect(body.queryByRole("menu", { name: "Unavailable" })).toBeNull();
},
});
+
+export const TestNestedMenusStayWithinViewport = meta.story({
+ name: "(Test) Nested menus stay within viewport",
+ globals: { viewport: { value: "narrow", isRotated: false } },
+ parameters: {
+ viewport: {
+ options: {
+ narrow: {
+ name: "Narrow phone",
+ styles: { width: "320px", height: "640px" },
+ },
+ },
+ },
+ },
+ args: {
+ placement: "bottom-end",
+ items: [
+ {
+ type: "item",
+ id: "copy-observation",
+ title: "Copy observation identifier",
+ onClick: fn(),
+ },
+ {
+ type: "submenu",
+ id: "add-to",
+ title: "Add to",
+ items: [
+ {
+ type: "submenu",
+ id: "datasets",
+ title: "Datasets",
+ search: { placeholder: "Search datasets…" },
+ items: [
+ {
+ type: "item",
+ id: "long-dataset",
+ title:
+ "Customer support quality evaluation with additional reference answers",
+ onClick: fn(),
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const document = canvasElement.ownerDocument;
+ const body = within(document.body);
+ const expectMenuWithinViewport = async (name: string) => {
+ const menu = await body.findByRole("menu", { name });
+ await waitFor(() => {
+ const bounds = menu.getBoundingClientRect();
+ expect(bounds.left).toBeGreaterThanOrEqual(0);
+ expect(bounds.right).toBeLessThanOrEqual(
+ document.documentElement.clientWidth,
+ );
+ });
+ };
+
+ await userEvent.click(canvas.getByRole("button", { name: "Open menu" }));
+ await expectMenuWithinViewport("Actions");
+ await userEvent.click(body.getByRole("menuitem", { name: "Add to" }));
+ await expectMenuWithinViewport("Add to");
+ await userEvent.click(body.getByRole("menuitem", { name: "Datasets" }));
+ await expectMenuWithinViewport("Datasets");
+ const search = body.getByRole("searchbox", { name: "Search datasets…" });
+ await userEvent.type(search, "quality");
+ await expect(search).toHaveValue("quality");
+ await expect(
+ body.getByRole("menuitem", {
+ name: "Customer support quality evaluation with additional reference answers",
+ }),
+ ).toBeVisible();
+ },
+});
diff --git a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
index 13d9ab465f..240d4390ba 100644
--- a/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
+++ b/web/src/components/design-system/DropdownMenu/DropdownMenu.tsx
@@ -33,7 +33,7 @@ import { useScrollGradients } from "@/src/hooks/useScrollGradients";
import { Checkbox } from "@/src/components/design-system/Checkbox/Checkbox";
const menuVariants = cva(
- "bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-95 min-w-32 overflow-y-auto rounded-md border shadow-md outline-hidden",
+ "bg-popover text-popover-foreground animate-in fade-in-0 zoom-in-95 min-w-32 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-md border shadow-md outline-hidden",
);
const menuBodyVariants = cva(
@@ -207,7 +207,7 @@ function DropdownMenuNode({
if (open) tree?.events.emit("menuopen", { nodeId, parentId });
},
placement,
- middleware: [offset(4), flip(), shift({ padding: 8 })],
+ middleware: [offset(4), flip(), shift({ padding: 8, crossAxis: true })],
transform: false,
whileElementsMounted: autoUpdate,
});