fix(webui): anchor floating surface animations (#6722)

* fix(webui): anchor floating surface animations

* test(webui): assert the dispatched file menu click coordinate
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 15:05:42 +08:00
1 parent eb82ab84cc
commit 32bba3a16c
7 files changed
+80 -4

No files matched your search

+13
View File
@@ -1,5 +1,6 @@
import { useRef, useState } from "react";
import { FileActions } from "@/components/FileActions";
import { Button } from "@/components/ui/button";
import { Disclosure } from "@/components/ui/disclosure";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
@@ -7,6 +8,7 @@ import { Input } from "@/components/ui/input";
import { sidePanelSurfaceClassName } from "@/components/ui/floating-surface";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { SidebarPanel } from "@/components/ui/sidebar-panel";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
export function ContinuityFixture() {
const [open, setOpen] = useState(false);
@@ -14,6 +16,17 @@ export function ContinuityFixture() {
const close = () => { setOpen(false); trigger.current?.focus(); };
return <main className="mx-auto flex min-h-screen max-w-5xl flex-col gap-6 px-5 py-12">
<h1 className="text-title">Interaction continuity</h1>
<div className="fixed right-4 top-1 z-10 flex gap-2">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild><Button>Help</Button></TooltipTrigger>
<TooltipContent side="top">Keyboard help</TooltipContent>
</Tooltip>
</TooltipProvider>
<FileActions path="notes/report.md" metadata={{ path: "notes/report.md", relative_path: "notes/report.md" }}>
<Button>Report file</Button>
</FileActions>
</div>
<div className="flex flex-wrap gap-3">
<DropdownMenu>
<DropdownMenuTrigger asChild><Button variant="outline">Conversation actions</Button></DropdownMenuTrigger>
+38
View File
@@ -55,6 +55,44 @@ for (const name of ["Conversation actions", "Quick note"]) {
}
}
test("a tooltip scales from the trigger-facing edge after flipping", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 720 });
await page.goto("/browser/fixture.html?case=continuity");
await page.getByRole("button", { name: "Help", exact: true }).hover();
const tip = page.locator('[data-side][data-state="delayed-open"]').filter({ hasText: "Keyboard help" });
await expect(tip).toHaveAttribute("data-side", "bottom");
await expect(tip).toHaveCSS("transform-origin", /px 0px$/);
});
for (const input of ["pointer", "keyboard"]) {
test(`the file menu scales from its ${input} anchor after shifting into the viewport`, async ({ page }) => {
await page.setViewportSize({ width: 390, height: 720 });
await page.goto("/browser/fixture.html?case=continuity");
const trigger = page.getByRole("button", { name: "Report file" });
const bounds = (await trigger.boundingBox())!;
const anchorX = input === "pointer" ? Math.floor(bounds.x + bounds.width - 6) : Math.round(bounds.x);
if (input === "pointer") await page.mouse.click(anchorX, Math.floor(bounds.y + bounds.height / 2), { button: "right" });
else await trigger.press("Shift+F10");
const menu = page.getByRole("menu");
await expect(menu).toHaveAttribute("data-side", "bottom");
await expect.poll(() => menu.evaluate(node => {
const [x, y] = getComputedStyle(node).transformOrigin.split(" ").map(Number.parseFloat);
return { x: Math.round(node.parentElement!.getBoundingClientRect().left + x), y };
})).toEqual({ x: anchorX, y: 0 });
await menu.press("Escape");
await expect(trigger).toBeFocused();
});
}
test("a tooltip opens without scaling when reduced motion is requested", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce" });
await page.goto("/browser/fixture.html?case=continuity");
await page.getByRole("button", { name: "Help", exact: true }).focus();
const tip = page.locator('[data-side][data-state="instant-open"]').filter({ hasText: "Keyboard help" });
await expect(tip).toHaveAttribute("data-side", "bottom");
await expect(tip).toHaveCSS("animation-name", "none");
});
test("a sidebar follows its actual exit and preserves an interrupted editor", async ({ page }) => {
await page.goto("/browser/fixture.html?case=continuity");
const toggle = page.getByRole("button", { name: "Toggle details", exact: true });
+24
View File
@@ -53,6 +53,30 @@ test("model picker keyboard Escape returns visible focus to its trigger", async
expect(await trigger.evaluate((node) => node.matches(":focus-visible"))).toBe(true);
});
test("the model picker enters from the trigger after flipping below it", async () => {
await page.setViewportSize({ width: 390, height: 720 });
const trigger = page.getByRole("button", { name: "First model", exact: true });
// Leave no room above the trigger so the preferred top placement must flip.
await trigger.evaluate(node => Object.assign(node.style, { position: "fixed", top: "4px" }));
await page.evaluate(() => {
document.addEventListener("animationstart", event => {
const node = event.target;
if (!(node instanceof HTMLElement) || node.getAttribute("role") !== "dialog") return;
const entry = node.getAnimations().find(animation => animation instanceof CSSAnimation);
if (!entry) return;
entry.pause();
entry.currentTime = 0;
});
});
await trigger.click();
const picker = page.getByRole("dialog");
await expect(picker).toHaveAttribute("data-side", "bottom");
await expect.poll(() => picker.evaluate(node => {
const transform = getComputedStyle(node).transform;
return transform === "none" ? 0 : new DOMMatrixReadOnly(transform).m42;
})).toBeLessThan(0);
});
test("model picker management handoff keeps focus in the new dialog", async () => {
await page.getByRole("button", { name: "First model", exact: true }).click();
await settleClose(() => page.getByRole("button", { name: "Manage presets" }).click());