Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix(homepage): release design link focus during scene exit (RX-198)

Amruth Pillaie719f226d4ee
diff --git a/apps/web/src/features/homepage/design.tsx b/apps/web/src/features/homepage/design.tsx
index 481941e6d..835013d59 100644
--- a/apps/web/src/features/homepage/design.tsx
+++ b/apps/web/src/features/homepage/design.tsx
@@ -48,11 +48,13 @@ const pageLabel = "font-martian font-medium text-[calc(var(--pw)*.045)] leading-
export function Design() {
const step = useLanding((state) => state.designStep);
const zoomed = useLanding((state) => state.designZoomed);
+ const exiting = useLanding((state) => state.designExiting);
const active = useLanding((state) => state.activeScene === SCENE.design);
const design = t`Design`;
const templateCount = i18n.number(templateSchema.options.length);
const templateNames = sheetTemplates.map((template) => i18n._(template.name));
const railRef = useRef<HTMLDivElement>(null);
+ const linkRef = useRef<HTMLAnchorElement>(null);
// On narrow screens the tab rail scrolls; keep the current look in view.
useEffect(() => {
@@ -62,6 +64,11 @@ export function Design() {
rail.scrollTo({ left: checked.offsetLeft - rail.clientWidth / 2 + checked.offsetWidth / 2, behavior: "smooth" });
}, [step]);
+ // The heading fades out as the scene leaves; release focus instead of leaving an outline on invisible text.
+ useEffect(() => {
+ if (exiting) linkRef.current?.blur();
+ }, [exiting]);
+
return (
<section
id="design"
@@ -218,7 +225,12 @@ export function Design() {
aria-label={`${t`${templateCount} free resume templates.`} ${t`Make any of them yours.`}`}
className="pointer-events-none absolute inset-x-(--gutter) top-[10vh] bottom-[8vh] [transform:translateY(calc((1-var(--z))*30px))] text-center text-[8vw] leading-none font-normal text-balance opacity-[calc(clamp(0,(var(--z)-.18)/.1,1)*(1-clamp(0,(var(--out)-.6)/.06,1)))] will-change-[transform,opacity] min-[900px]:bottom-[5vh] min-[900px]:text-[clamp(36px,4vw,72px)]"
>
- <Link to="/resume-templates" inert={!zoomed} className="flex h-full flex-col justify-between">
+ <Link
+ ref={linkRef}
+ to="/resume-templates"
+ inert={!zoomed || exiting}
+ className="flex h-full flex-col justify-between"
+ >
<span className="font-anybody pointer-events-auto font-light tracking-[-.02em] text-ink">
{t`${templateCount} free resume templates.`}
</span>
diff --git a/apps/web/src/features/homepage/scroll.test.ts b/apps/web/src/features/homepage/scroll.test.tsx
similarity index 59%
rename from apps/web/src/features/homepage/scroll.test.ts
rename to apps/web/src/features/homepage/scroll.test.tsx
index 8e59c92e2..09ea479e5 100644
--- a/apps/web/src/features/homepage/scroll.test.ts
+++ b/apps/web/src/features/homepage/scroll.test.tsx
@@ -1,5 +1,8 @@
+// @vitest-environment happy-dom
+import { cleanup, fireEvent, render, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
-import { goToScene, sectionExitProgress, sectionProgress, useLanding } from "./scroll";
+import { useRef } from "react";
+import { goToScene, SCENE, sectionExitProgress, sectionProgress, useLanding, useScrollScenes } from "./scroll";
describe("section progress", () => {
it("measures a pinned scene by how far its sticky stage has travelled", () => {
@@ -25,6 +28,63 @@ describe("scene exit", () => {
});
});
+describe("scroll engine", () => {
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+ useLanding.setState({ designExiting: false });
+ });
+
+ it("writes exit progress on pinned scenes and reports when Design hands its heading off", async () => {
+ const rects = new Map<string, { top: number; bottom: number; height: number }>([
+ [String(SCENE.design), { top: 0, bottom: 300, height: 900 }],
+ [String(SCENE.check), { top: 0, bottom: 0, height: 900 }],
+ ]);
+ vi.stubGlobal("innerHeight", 900);
+ vi.stubGlobal("matchMedia", () => ({ matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() }));
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {
+ const rect = rects.get(this.dataset.scene ?? "") ?? { top: 0, bottom: 0, height: 0 };
+ return {
+ ...rect,
+ left: 0,
+ right: 0,
+ width: 0,
+ x: 0,
+ y: 0,
+ toJSON: () => ({}),
+ } as DOMRect;
+ });
+
+ function Scenes() {
+ const root = useRef<HTMLDivElement>(null);
+ useScrollScenes(root);
+ return (
+ <div ref={root}>
+ <section data-scene={SCENE.design} data-pin />
+ <section data-scene={SCENE.check} data-pin />
+ <section data-scene={SCENE.tailor} />
+ </div>
+ );
+ }
+
+ render(<Scenes />);
+ const design = document.querySelector<HTMLElement>(`[data-scene="${SCENE.design}"]`);
+ const tailor = document.querySelector<HTMLElement>(`[data-scene="${SCENE.tailor}"]`);
+ if (!design || !tailor) throw new Error("The scene harness did not render.");
+
+ await waitFor(() => expect(design.style.getPropertyValue("--out")).toBe("0.667"));
+ expect(design.style.getPropertyValue("--out")).toBe("0.667");
+ expect(useLanding.getState().designExiting).toBe(true);
+ expect(tailor.style.getPropertyValue("--out")).toBe("");
+
+ rects.set(String(SCENE.design), { top: 0, bottom: 600, height: 900 });
+ fireEvent.scroll(window);
+ await waitFor(() => expect(design.style.getPropertyValue("--out")).toBe("0.333"));
+ expect(useLanding.getState().designExiting).toBe(false);
+ });
+});
+
describe("scene navigation", () => {
afterEach(() => vi.unstubAllGlobals());
it.each(["wheel", "touchmove", "PageDown", "ArrowDown", " ", "a"])(
diff --git a/apps/web/src/features/homepage/scroll.ts b/apps/web/src/features/homepage/scroll.ts
index dbe533a8c..833af75b7 100644
--- a/apps/web/src/features/homepage/scroll.ts
+++ b/apps/web/src/features/homepage/scroll.ts
@@ -34,6 +34,8 @@ type LandingState = {
designStep: number;
/** Design: zoomed out to the contact sheet, so the template tabs are gone. */
designZoomed: boolean;
+ /** Design: far enough into its exit that the closing heading is fading, so its link leaves the tab order. */
+ designExiting: boolean;
/** Check: the scan's progress, in 40 steps, which drives the score and the checklist. */
checkProgress: number;
/** Tailor: how many of the posting's four keywords are matched. */
@@ -57,6 +59,7 @@ export const useLanding = create<LandingState>()(() => ({
writeStep: 0,
designStep: 0,
designZoomed: false,
+ designExiting: false,
checkProgress: 0,
keywordCount: 0,
shareReady: false,
@@ -73,6 +76,9 @@ const PREPARE_STEPS = [0.19, 0.36, 0.53, 0.7, 0.84];
const smoothstep = (value: number) => value * value * (3 - 2 * value);
+/** Where Design's closing heading starts fading out of the scene, and where its link stops taking focus. */
+const DESIGN_EXIT_AT = 0.6;
+
/**
* How dark Share's sky is, from 0 to 1: night falls over the scene's first fifth and lifts into dawn over its last
* stretch, both eased, so neither end snaps. The engine writes it as --nt on Share and on the page, for the header.
@@ -284,7 +290,9 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
const reduced = reducedMotion.matches;
const progress: number[] = [];
const nearby = new Set<number>();
+ const exits: { section: HTMLElement; value: string }[] = [];
let activeScene: number = SCENE.hero;
+ let designExiting = false;
for (const section of sections) {
const index = Number(section.dataset.scene);
@@ -293,11 +301,10 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
const pinned = section.dataset.pin !== undefined;
progress[index] = reduced ? 1 : sectionProgress(rect.top, rect.height, viewportHeight, pinned);
if (pinned) {
- const exit = sectionExitProgress(rect.bottom, viewportHeight).toFixed(3);
- if (writtenExit.get(section) !== exit) {
- section.style.setProperty("--out", exit);
- writtenExit.set(section, exit);
- }
+ const exit = sectionExitProgress(rect.bottom, viewportHeight);
+ if (index === SCENE.design) designExiting = exit >= DESIGN_EXIT_AT;
+ const value = exit.toFixed(3);
+ if (writtenExit.get(section) !== value) exits.push({ section, value });
}
if (rect.top <= viewportHeight / 2 && rect.bottom > viewportHeight / 2) activeScene = index;
}
@@ -316,6 +323,11 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
}
const tailorSection = sectionAt(SCENE.tailor);
if (tailorSection && nearby.has(SCENE.tailor) && window.innerWidth >= 900) drawThreads(tailorSection);
+ // Every geometry read above is done, so the exit writes can't force a second layout mid-measure.
+ for (const { section, value } of exits) {
+ section.style.setProperty("--out", value);
+ writtenExit.set(section, value);
+ }
for (const section of sections) {
const value = (progress[Number(section.dataset.scene)] ?? 0).toFixed(4);
if (writtenProgress.get(section) === value) continue;
@@ -371,6 +383,7 @@ export function useScrollScenes(root: RefObject<HTMLElement | null>) {
writeStep: at(SCENE.write) >= 0.84 ? 2 : at(SCENE.write) >= 0.4 ? 1 : 0,
designStep: stepsPassed(at(SCENE.design), [0.15, 0.31, 0.47, 0.63]),
designZoomed: at(SCENE.design) >= 0.84,
+ designExiting,
checkProgress: Math.round(scan * 40) / 40,
keywordCount: stepsPassed(at(SCENE.tailor), [0.19, 0.31, 0.43, 0.55]),
shareReady: at(SCENE.share) >= 0.66,