# Mobile Portal Navigation Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Add an accessible mobile-only dropdown that exposes every role-specific portal destination, theme control and sign-out action while leaving desktop navigation unchanged. **Architecture:** A focused client component owns the dropdown interaction and receives the existing `NavItem[]` from the server-rendered `PortalShell`. `PortalShell` renders this component only for mobile layouts and keeps its existing desktop controls behind the `sm` breakpoint, avoiding duplicated route catalogues or new dependencies. **Tech Stack:** Next.js 16 App Router, React 19, TypeScript, Tailwind CSS 4, Lucide React, Vitest, Testing Library, jsdom. ## Global Constraints - The mobile menu is visible only below the Tailwind `sm` breakpoint. - The existing desktop navigation, route names, authorization and sign-out behavior remain unchanged. - The component consumes the existing role-specific `nav: NavItem[]`; no second navigation catalogue is allowed. - The menu closes on link activation, Escape and outside pointer interaction. - Escape returns focus to the trigger. - The active route uses `aria-current="page"` and a high-contrast visual state. - Touch targets are at least 44 pixels high. - No new runtime dependency or animation framework may be added. --- ### Task 1: Accessible mobile dropdown behavior **Files:** - Create: `src/components/layout/mobile-portal-menu.tsx` - Create: `src/components/layout/mobile-portal-menu.test.tsx` **Interfaces:** - Consumes: `NavItem` from `@/components/layout/portal-shell`, `ThemeToggle`, `LogoutButton`, and `usePathname()`. - Produces: `MobilePortalMenu({ nav, sectionLabel }: { nav: NavItem[]; sectionLabel: string }): JSX.Element`. - [ ] **Step 1: Write the failing interaction tests** Create `src/components/layout/mobile-portal-menu.test.tsx` with jsdom, a controlled `usePathname()` mock, and real child controls: ```tsx // @vitest-environment jsdom import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { afterEach, beforeEach, expect, test, vi } from "vitest"; const { usePathname } = vi.hoisted(() => ({ usePathname: vi.fn(), })); vi.mock("next/navigation", () => ({ usePathname })); import { MobilePortalMenu } from "./mobile-portal-menu"; const nav = [ { href: "/admin", label: "Dashboard" }, { href: "/admin/redaktionen", label: "Redaktionen" }, { href: "/admin/abrechnungen", label: "Abrechnungen" }, { href: "/admin/audit", label: "Audit" }, ]; beforeEach(() => usePathname.mockReturnValue("/admin/redaktionen/abc")); afterEach(cleanup); test("opens every mobile portal action and marks the most specific active route", () => { render(); const trigger = screen.getByRole("button", { name: /menü öffnen/i }); expect(trigger.getAttribute("aria-expanded")).toBe("false"); expect(screen.queryByRole("navigation", { name: /mobile navigation/i })).toBeNull(); fireEvent.click(trigger); expect(trigger.getAttribute("aria-expanded")).toBe("true"); expect(screen.getByRole("link", { name: "Dashboard" })).toBeTruthy(); expect(screen.getByRole("link", { name: "Redaktionen" }).getAttribute("aria-current")).toBe("page"); expect(screen.getByRole("link", { name: "Abrechnungen" })).toBeTruthy(); expect(screen.getByRole("link", { name: "Audit" })).toBeTruthy(); expect(screen.getByRole("button", { name: /design umschalten/i })).toBeTruthy(); expect(screen.getByRole("button", { name: /abmelden/i })).toBeTruthy(); }); test("closes after navigation, Escape and an outside pointer interaction", () => { render(
, ); const trigger = screen.getByRole("button", { name: /menü öffnen/i }); fireEvent.click(trigger); fireEvent.click(screen.getByRole("link", { name: "Audit" })); expect(trigger.getAttribute("aria-expanded")).toBe("false"); fireEvent.click(trigger); fireEvent.keyDown(document, { key: "Escape" }); expect(trigger.getAttribute("aria-expanded")).toBe("false"); expect(document.activeElement).toBe(trigger); fireEvent.click(trigger); fireEvent.pointerDown(screen.getByRole("button", { name: "Außerhalb" })); expect(trigger.getAttribute("aria-expanded")).toBe("false"); }); ``` - [ ] **Step 2: Run the focused test and verify RED** Run: ```bash ./node_modules/.bin/vitest run src/components/layout/mobile-portal-menu.test.tsx ``` Expected: FAIL because `./mobile-portal-menu` does not exist. - [ ] **Step 3: Implement the minimal client component** Create `src/components/layout/mobile-portal-menu.tsx`: ```tsx "use client"; import { useEffect, useMemo, useRef, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { Menu, X } from "lucide-react"; import type { NavItem } from "@/components/layout/portal-shell"; import { LogoutButton } from "@/components/layout/logout-button"; import { ThemeToggle } from "@/components/theme-toggle"; type MobilePortalMenuProps = { nav: NavItem[]; sectionLabel: string; }; export function MobilePortalMenu({ nav, sectionLabel }: Readonly) { const pathname = usePathname(); const [open, setOpen] = useState(false); const containerRef = useRef(null); const triggerRef = useRef(null); const menuId = "mobile-portal-menu"; const activeHref = useMemo( () => nav .filter(({ href }) => pathname === href || pathname.startsWith(`${href}/`)) .sort((left, right) => right.href.length - left.href.length)[0]?.href, [nav, pathname], ); useEffect(() => { if (!open) return; function closeOnOutsidePointer(event: PointerEvent) { if (!containerRef.current?.contains(event.target as Node)) setOpen(false); } function closeOnEscape(event: KeyboardEvent) { if (event.key !== "Escape") return; setOpen(false); triggerRef.current?.focus(); } document.addEventListener("pointerdown", closeOnOutsidePointer); document.addEventListener("keydown", closeOnEscape); return () => { document.removeEventListener("pointerdown", closeOnOutsidePointer); document.removeEventListener("keydown", closeOnEscape); }; }, [open]); return (
{open ? (

{sectionLabel}

Darstellung
) : null}
); } ``` - [ ] **Step 4: Run the focused test and verify GREEN** Run: ```bash ./node_modules/.bin/vitest run src/components/layout/mobile-portal-menu.test.tsx ``` Expected: 1 file and 2 tests PASS. - [ ] **Step 5: Run typecheck and lint for the new boundary** Run: ```bash ./node_modules/.bin/tsc --noEmit ./node_modules/.bin/eslint src/components/layout/mobile-portal-menu.tsx src/components/layout/mobile-portal-menu.test.tsx ``` Expected: both commands exit 0 with no errors. - [ ] **Step 6: Commit the independently tested component** ```bash git add src/components/layout/mobile-portal-menu.tsx src/components/layout/mobile-portal-menu.test.tsx git commit -m "feat: add accessible mobile portal menu" ``` ### Task 2: Integrate the menu into the shared portal shell **Files:** - Modify: `src/components/layout/portal-shell.tsx` - Modify: `src/components/brand/logo.test.tsx` **Interfaces:** - Consumes: `MobilePortalMenu({ nav, sectionLabel })` from Task 1 and the existing `PortalShellProps`. - Produces: one shared responsive header used unchanged by `src/app/admin/layout.tsx` and `src/app/redaktion/layout.tsx`. - [ ] **Step 1: Extend the existing shell test with the mobile contract** In `src/components/brand/logo.test.tsx`, mock `usePathname()` before imports and extend the `PortalShell` test: ```tsx import { fireEvent, render, screen } from "@testing-library/react"; import { expect, test, vi } from "vitest"; vi.mock("next/navigation", () => ({ usePathname: () => "/redaktion/alben", })); // Existing tests remain. In the PortalShell test, add: const menuTrigger = screen.getByRole("button", { name: /menü öffnen/i }); expect(menuTrigger.parentElement?.className).toContain("sm:hidden"); fireEvent.click(menuTrigger); expect(screen.getAllByRole("link", { name: "Alben" })).toHaveLength(2); expect(screen.getByRole("navigation", { name: /mobile navigation/i })).toBeTruthy(); ``` The two `Alben` links demonstrate that the unchanged desktop link and the mobile dropdown consume the same supplied `nav` entry. The CSS visibility classes ensure only one is exposed visually at a given breakpoint. - [ ] **Step 2: Run the shell test and verify RED** Run: ```bash ./node_modules/.bin/vitest run src/components/brand/logo.test.tsx ``` Expected: FAIL because `PortalShell` does not yet expose the mobile trigger. - [ ] **Step 3: Integrate mobile and desktop control groups** Modify `src/components/layout/portal-shell.tsx`: ```tsx import { MobilePortalMenu } from "@/components/layout/mobile-portal-menu"; // Inside the right-hand header container, preserve sectionLabel and desktop nav, // replace the always-visible controls with:
``` Keep the existing desktop `