fix: smooth advanced focus entrance

This commit is contained in:
Thomas Camlong authored and ajnart committed 2026-08-14 11:07:08 +02:00
1 parent 7c840bcfa0
commit a0f4a58386
3 files changed
+81

No files matched your search

@@ -16,9 +16,15 @@
box-shadow: var(--mantine-shadow-md);
overscroll-behavior: contain;
animation: focus-surface-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
animation-fill-mode: backwards;
animation-play-state: paused;
transform-origin: top left;
}
.surfaceReady {
animation-play-state: running;
}
.manualSurface {
position: fixed;
max-width: none;
@@ -0,0 +1,62 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, test, vi } from "vitest";
import { startAdvancedFocusEntrance } from "./entrance";
describe("startAdvancedFocusEntrance", () => {
afterEach(() => {
document.body.replaceChildren();
vi.unstubAllGlobals();
});
test("moves the persistent portal before releasing its source-frame animation", () => {
let releaseFrame: FrameRequestCallback | undefined;
vi.stubGlobal(
"requestAnimationFrame",
vi.fn((callback: FrameRequestCallback) => {
releaseFrame = callback;
return 7;
}),
);
const compactHost = document.createElement("div");
const previewHost = document.createElement("div");
const portalTarget = document.createElement("div");
const surface = document.createElement("div");
surface.classList.add("surface-ready");
portalTarget.append(surface);
compactHost.append(portalTarget);
document.body.append(compactHost, previewHost);
expect(startAdvancedFocusEntrance(portalTarget, previewHost, surface, "surface-ready")).toBe(7);
expect(portalTarget.parentElement).toBe(previewHost);
expect(surface.classList.contains("surface-ready")).toBe(false);
releaseFrame?.(0);
expect(surface.classList.contains("surface-ready")).toBe(true);
});
test("does not release a detached surface", () => {
let releaseFrame: FrameRequestCallback | undefined;
vi.stubGlobal(
"requestAnimationFrame",
vi.fn((callback: FrameRequestCallback) => {
releaseFrame = callback;
return 8;
}),
);
const previewHost = document.createElement("div");
const portalTarget = document.createElement("div");
const surface = document.createElement("div");
portalTarget.append(surface);
document.body.append(previewHost);
startAdvancedFocusEntrance(portalTarget, previewHost, surface, "surface-ready");
portalTarget.remove();
releaseFrame?.(0);
expect(surface.classList.contains("surface-ready")).toBe(false);
});
});
@@ -0,0 +1,13 @@
export const startAdvancedFocusEntrance = (
portalTarget: HTMLElement,
host: HTMLElement,
surface: HTMLElement,
readyClass: string,
) => {
host.append(portalTarget);
surface.classList.remove(readyClass);
return requestAnimationFrame(() => {
if (surface.isConnected) surface.classList.add(readyClass);
});
};