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:
1 parent
eb82ab84cc
commit
32bba3a16c
7 files changed
+80
-4
No files matched your search
+1
-1
@@ -62,7 +62,7 @@ Prompt navigation keeps a three-page raw window. Fragmented turns also retain th
|
||||
|
||||
The application theme remains the single owner for paired day/night artwork. The Sidebar keeps the original daytime mark and uses a sleeping-cap variant in dark mode; the Star invitation pairs matching day/night illustrations. Both layers reserve the same geometry. `.theme-art` blends opacity for System changes and browsers without native snapshots; a native root View Transition owns the whole-frame fade instead. Reduced motion switches artwork directly. Entry and conversation surfaces keep their normal theme colors without decorative ambient glow.
|
||||
|
||||
Dropdowns and popovers use Radix's resolved transform origin and side, so motion stays attached to the trigger after collision handling. Radix owns their presence and focus. `SidebarPanel` retains its content until the slot and surface finish their actual exit animations, ignores descendant activity, and cancels teardown when reopened. Closing content is inert and hidden from assistive navigation; callers still own focus restoration. Disclosures keep their existing in-flow height transition and draft retention.
|
||||
Dropdowns, popovers, and tooltips use Radix's resolved transform origin so scaling stays on the trigger-facing edge after collision handling. The file context menu uses the pointer location or the focused file as its anchor. Surfaces with slide motion use the resolved side. Radix owns their presence and focus. `SidebarPanel` retains its content until the slot and surface finish their actual exit animations, ignores descendant activity, and cancels teardown when reopened. Closing content is inert and hidden from assistive navigation; callers still own focus restoration. Disclosures keep their existing in-flow height transition and draft retention.
|
||||
|
||||
## Typography
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -114,7 +114,7 @@ export function FileActions({
|
||||
<Menu.Portal container={portal ?? undefined}>
|
||||
<Menu.Content aria-label={t("fileActions.menu", { name: path.split(/[\\/]/).pop() || path })}
|
||||
align="start" sideOffset={4} collisionPadding={12}
|
||||
className={cn(floatingSurfaceClassName, floatingSurfaceMotionClassName, "min-w-40 rounded-control p-1 [&_[role=menuitem]]:py-1.5")}
|
||||
className={cn(floatingSurfaceClassName, floatingSurfaceMotionClassName, "min-w-40 origin-[var(--radix-popper-transform-origin)] rounded-control p-1 [&_[role=menuitem]]:py-1.5")}
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onContextMenu={(event) => { event.preventDefault(); event.stopPropagation(); }}
|
||||
onInteractOutside={() => { interactedOutside.current = true; }}
|
||||
@@ -122,6 +122,8 @@ export function FileActions({
|
||||
event.preventDefault();
|
||||
if (!interactedOutside.current) opener.current?.focus();
|
||||
}}>
|
||||
{/* Track the click point even when collision handling shifts the menu; render no visible arrow. */}
|
||||
<Menu.Arrow width={0} height={0} aria-hidden />
|
||||
<Menu.Item className={itemClassName} disabled={!resolved} onSelect={(event) => {
|
||||
event.preventDefault();
|
||||
if (resolved) void copy(resolved.path);
|
||||
|
||||
@@ -434,7 +434,6 @@ export function ModelPresetBadge({
|
||||
className={cn(
|
||||
showsSpeedControl ? speedPickerWidthClassName : pickerWidthClassName,
|
||||
"inset-scrollbar flex max-h-[var(--radix-popover-content-available-height)] flex-col overflow-y-auto",
|
||||
"origin-[var(--radix-popover-content-transform-origin)] p-1.5 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-bottom-1 data-[state=open]:slide-in-from-bottom-1 duration-200 ease-out motion-reduce:animate-none",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -23,7 +23,7 @@ const TooltipContent = React.forwardRef<
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
floatingSurfaceElevationClassName,
|
||||
"z-50 overflow-hidden rounded-control px-3 py-1.5 text-caption animate-in fade-in-0 zoom-in-95",
|
||||
"z-50 origin-[var(--radix-tooltip-content-transform-origin)] overflow-hidden rounded-control px-3 py-1.5 text-caption animate-in fade-in-0 zoom-in-95 motion-reduce:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
Reference in new issue
Block a user