diff --git a/web/e2e/mobile-header.e2e.ts b/web/e2e/mobile-header.e2e.ts new file mode 100644 index 0000000..af28cd1 --- /dev/null +++ b/web/e2e/mobile-header.e2e.ts @@ -0,0 +1,53 @@ +// The recovered mobile menu keeps rich section rows and native keyboard/dismissal behavior. +import { expect, test } from "@playwright/test"; + +for (const width of [320, 390, 768, 900]) { + test(`mobile sections at ${width}px`, async ({ page }) => { + await page.setViewportSize({ width, height: 740 }); + await page.goto("/dev/ui"); + const trigger = page.getByRole("button", { name: "Sections", exact: true }); + const menu = page.getByRole("menu"); + await trigger.click(); + await expect(menu).toBeVisible(); + await expect( + menu.getByText("Every map, with its tier and world record"), + ).toBeVisible(); + await expect(menu.getByRole("menuitem")).toHaveCount(11); + await expect( + menu.getByRole("menuitem", { name: "Discord", exact: true }), + ).toHaveAttribute("href", "https://discord.gg/RYP5G4tuwX"); + const headerBox = (await page.getByRole("banner").boundingBox())!; + expect((await menu.boundingBox())!.y).toBe(headerBox.y + headerBox.height); + expect( + await menu.evaluate( + (element) => element.scrollWidth <= element.clientWidth, + ), + ).toBe(true); + await page.keyboard.press("End"); + await expect( + menu.getByRole("menuitem", { name: "Instagram", exact: true }), + ).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(menu).toBeHidden(); + await expect(trigger).toBeFocused(); + await trigger.click(); + await menu.getByRole("menuitem", { name: "Ruleset", exact: true }).click(); + await expect(page).toHaveURL(/\/ruleset$/); + await expect(menu).toBeHidden(); + await trigger.click(); + await page.mouse.click(width - 5, 730); + await expect(menu).toBeHidden(); + }); +} + +test("desktop keeps the current header", async ({ page }) => { + await page.goto("/dev/ui"); + await expect( + page.getByRole("button", { name: "Sections", exact: true }), + ).toBeHidden(); + await expect( + page + .getByRole("navigation", { name: "Main", exact: true }) + .getByRole("link", { name: "Records", exact: true }), + ).toBeVisible(); +}); diff --git a/web/src/features/site/MobileSiteNav.tsx b/web/src/features/site/MobileSiteNav.tsx new file mode 100644 index 0000000..868c693 --- /dev/null +++ b/web/src/features/site/MobileSiteNav.tsx @@ -0,0 +1,144 @@ +"use client"; +// Header navigation: section links on wide screens; on narrow ones, a menu that opens as a panel under the header, +// each section with what's in it, and the ruleset and community at its foot. Marks the current section. +import { + Activity, + type LucideIcon, + Map as MapIcon, + Menu as MenuIcon, + ScrollText, + Server, + Trophy, + Users, + X, +} from "lucide-react"; +import type { CSSProperties } from "react"; +import { Link } from "@/ui/Link"; +import { BrandIcon } from "@/ui/BrandIcon"; +import { classNames } from "@/ui/classNames"; +import { Menu } from "@/ui/Menu"; +import { communityLinks, isCurrent, sections } from "./navigation"; + +const icons: Record<(typeof sections)[number]["href"], LucideIcon> = { + "/leaderboards": Trophy, + "/maps": MapIcon, + "/players": Users, + "/activity": Activity, + "/servers": Server, +}; + +import styles from "./SiteHeader.module.css"; + +// Recovered from the navigation before the desktop header redesign. +export function MobileSiteNav({ pathname }: { pathname: string | null }) { + return ( +
+ + + + + } + triggerClassName="group flex size-10 items-center justify-center rounded-md text-text-muted hover:bg-surface-raised hover:text-text aria-expanded:bg-surface-raised aria-expanded:text-text" + > +
    + {sections.map(({ href, label, summary }, index) => { + const current = isCurrent(href, pathname); + const Icon = icons[href]; + return ( +
  • + {/* The current section's mark is the desktop underline turned on its side. */} + + + + + + + {label} + + + {summary} + + + +
  • + ); + })} +
+
+ + + Ruleset + + + {communityLinks.map(({ label, brand, href }) => ( + + + + ))} + +
+
+
+ ); +} diff --git a/web/src/features/site/SiteHeader.module.css b/web/src/features/site/SiteHeader.module.css index 9607864..d2f18fc 100644 --- a/web/src/features/site/SiteHeader.module.css +++ b/web/src/features/site/SiteHeader.module.css @@ -135,52 +135,13 @@ .nav { display: none; } + .mobileMenu [role="menu"] { + top: var(--site-header-height); + } .mobileMenu { display: block; - } - .mobileMenu summary { - display: flex; - min-height: 44px; - align-items: center; - gap: 8px; - cursor: pointer; - list-style: none; - font-size: 13px; - } - .mobileMenu summary::-webkit-details-marker { - display: none; - } - .mobileMenu summary svg { - width: 20px; - height: 20px; - transition: transform 200ms; - } - .mobileMenu[open] summary svg { - transform: rotate(45deg); - } - .mobileLinks { - position: absolute; - top: 100%; - right: 16px; - left: 16px; - display: flex; - max-height: calc(100svh - var(--site-header-height) - 24px); - flex-direction: column; - overflow-y: auto; - padding: 16px 24px; - border-radius: 18px; - background: #101b2af5; - backdrop-filter: blur(24px); - } - .mobileLinks a { - display: flex; - min-height: 48px; - flex-shrink: 0; - align-items: center; - font-size: 16px; - } - .mobileLinks a[aria-current="page"] { - color: #94c7ff; + order: -1; + margin-left: -8px; } } @media (max-width: 600px) { @@ -215,10 +176,6 @@ clip-path: inset(50%); white-space: nowrap; } - .mobileMenu summary { - gap: 4px; - font-size: 12px; - } } @media (max-width: 359px) { .shell { @@ -227,14 +184,6 @@ .wordmark { font-size: 18px; } - .mobileMenu summary { - font-size: 0; - gap: 0; - } - .mobileMenu summary svg { - width: 22px; - height: 22px; - } } @media (max-width: 1279px) { diff --git a/web/src/features/site/SiteHeader.tsx b/web/src/features/site/SiteHeader.tsx index 65e23bd..4c22d05 100644 --- a/web/src/features/site/SiteHeader.tsx +++ b/web/src/features/site/SiteHeader.tsx @@ -1,6 +1,5 @@ import { Suspense } from "react"; import { Play } from "next/font/google"; -import { Plus } from "lucide-react"; import { Link } from "@/ui/Link"; import { AccountArea } from "./AccountArea"; import { HeaderSearch } from "./HeaderSearch"; @@ -36,14 +35,9 @@ export function SiteHeader() { -
- - Menu - - }> - - -
+ + + ); diff --git a/web/src/features/site/SiteNav.tsx b/web/src/features/site/SiteNav.tsx index f41eaac..1216ee8 100644 --- a/web/src/features/site/SiteNav.tsx +++ b/web/src/features/site/SiteNav.tsx @@ -3,6 +3,7 @@ import { usePathname } from "next/navigation"; import { Link } from "@/ui/Link"; import { isCurrent } from "./navigation"; +import { MobileSiteNav } from "./MobileSiteNav"; import styles from "./SiteHeader.module.css"; const navigation = [ @@ -23,11 +24,9 @@ export function SiteNavLinks({ pathname: string | null; mobile?: boolean; }) { + if (mobile) return ; return ( -