Files
chrnx-dev-wp/docs/superpowers/plans/2026-08-11-mobile-header.md
T

17 KiB
Raw Blame History

CHRNX Mobile Header 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: Replace the wrapped mobile header with the approved single-row CHRNX bar and coordinated Search, Theme, and Menu panels.

Architecture: Keep the current server-rendered navigation, GET search, and native theme radios. Expand navigation.js into the single header controller, remove the separate search controller, and keep theme-toggle.js responsible only for preference storage and color application. At mobile widths the controller moves the existing controls into Search → Theme → Menu → Navigation DOM order; at 600 px it restores the original desktop order.

Tech Stack: WordPress block theme, PHP 8.3, vanilla JavaScript, CSS custom properties, Jest/jsdom, PHPUnit, Playwright, axe-core, wp-env on Colima.


File map

  • blocks/theme-toggle/render.php: render the mobile theme trigger and native radio panel with stable IDs and accessible state.
  • blocks/header-tools/render.php: expose stable search panel IDs; keep native GET submission.
  • blocks/header-tools/block.json: keep the search controller through Task 1, then transfer ownership to the navigation controller in Task 2.
  • assets/js/navigation.js: own mobile ordering and all three panel states.
  • assets/js/search.js: remove after its behavior moves into the controller.
  • assets/js/theme-toggle.js: retain preference resolution and storage only.
  • assets/css/layout.css: implement the compact row, search row, theme popover, menu panel, desktop invariant, no-JavaScript fallback, and reduced motion.
  • tests/js/navigation.test.js: cover controller state, focus, ordering, resize, cleanup, and native search submission.
  • tests/js/search.test.js: remove after merging its behavior tests.
  • tests/php/BlockRenderingTest.php: verify translated, escaped control markup.
  • tests/smoke/theme-preference-contract.test.mjs: verify script ownership and progressive markup.
  • tests/e2e/navigation.spec.mjs: verify real keyboard, layout, breakpoints, no-JavaScript behavior, and browser parity.
  • tests/e2e/theme-preference.spec.mjs: verify popover behavior and preference precedence through reload and operating-system changes.
  • scripts/capture-mobile-header-review.mjs: create eight header-only visual review artifacts without changing the uncommitted Task 7 capture script.

Task 0: Commit the approved documents in isolation

Files:

  • Modify: docs/superpowers/specs/2026-08-11-mobile-header-design.md

  • Create: docs/superpowers/plans/2026-08-11-mobile-header.md

  • Step 1: Verify and stage only the two documents

npx --yes markdownlint-cli2 \
  docs/superpowers/specs/2026-08-11-mobile-header-design.md \
  docs/superpowers/plans/2026-08-11-mobile-header.md
git add docs/superpowers/specs/2026-08-11-mobile-header-design.md \
  docs/superpowers/plans/2026-08-11-mobile-header.md
git diff --cached --check
git diff --cached -- \
  docs/superpowers/specs/2026-08-11-mobile-header-design.md \
  docs/superpowers/plans/2026-08-11-mobile-header.md

Expected: the staged diff contains only the approved Theme-focus refinement and this plan. It contains no Task 7 fixture, asset, seed, or visual-state files.

  • Step 2: Commit the documents
git commit -m "docs: plan compact CHRNX mobile header"

Task 1: Lock the accessible markup contract

Files:

  • Modify: blocks/theme-toggle/render.php

  • Modify: blocks/header-tools/render.php

  • Modify: assets/js/search.js

  • Modify: tests/php/BlockRenderingTest.php

  • Modify: tests/js/search.test.js

  • Modify: tests/smoke/theme-preference-contract.test.mjs

  • Step 1: Write failing PHP and smoke tests

Require one theme button with a stable aria-controls target, the target fieldset, a search button with matching aria-controls and server-rendered aria-expanded="true", and a visible controlled search-row ID. Keep search.js owned by the header-tools block so current enhanced behavior continues until Task 2. Preserve native radio and GET form semantics.

$this->assertSame( 1, substr_count( $html, 'data-chrnx-theme-button' ) );
$this->assertMatchesRegularExpression(
    '/aria-controls="([^"]+)"[^>]*aria-expanded="false"/',
    $html
);
$this->assertStringContainsString( 'data-chrnx-theme-panel', $html );
$this->assertStringContainsString( 'role="search"', $search_html );
$this->assertStringContainsString( 'method="get"', $search_html );
$this->assertMatchesRegularExpression(
    '/data-chrnx-search-button[^>]+aria-controls="([^"]+)"' .
    '[^>]+aria-expanded="true"/',
    $search_html
);
$this->assertStringContainsString( 'data-chrnx-search-panel', $search_html );
assert.match(headerToolsMetadata, /search\.js/);
assert.match(mobileMenuMetadata, /navigation\.js/);

Require the existing search controller to synchronize the enhanced state:

initialize({ document });
expect(searchPanel.hidden).toBe(true);
expect(searchButton.getAttribute('aria-expanded')).toBe('false');
openEmptySearch();
expect(searchButton.getAttribute('aria-expanded')).toBe('true');
pressEscape();
expect(searchButton.getAttribute('aria-expanded')).toBe('false');
  • Step 2: Run the focused tests and verify RED

Run:

PATH="/opt/homebrew/opt/docker/bin:$PATH" \
  npm run test:php -- --filter BlockRenderingTest
node --test tests/smoke/theme-preference-contract.test.mjs
npm run test:js -- --runInBand tests/js/search.test.js

Expected: FAIL because the theme trigger and panel IDs do not exist and the search button does not yet expose its visible server-rendered state.

  • Step 3: Implement minimal progressive markup

Render a wrapper containing:

<button type="button" hidden data-chrnx-theme-button
  aria-controls="chrnx-theme-panel-…" aria-expanded="false"
  aria-label="Choose color theme">◐</button>
<fieldset id="chrnx-theme-panel-…" data-chrnx-theme-toggle
  data-chrnx-theme-panel>…native radios…</fieldset>

Use wp_unique_id(), translation functions, context-appropriate escaping, and the existing status strings. Wrap the search input in a controlled search-row element with a stable ID. Point the Search button's aria-controls to that ID and render aria-expanded="true" while the no-JavaScript row is visible. Keep the native GET form and the header-tools block's existing search.js ownership. On initialization, search.js hides the controlled row and synchronizes the button to aria-expanded="false"; open and Escape synchronize both states.

  • Step 4: Run the focused tests and verify GREEN

Run the commands from Step 2.

Expected: PASS with no PHP warnings or Node test failures.

  • Step 5: Commit the markup contract
git add blocks/theme-toggle/render.php blocks/header-tools/render.php \
  assets/js/search.js tests/php/BlockRenderingTest.php \
  tests/js/search.test.js \
  tests/smoke/theme-preference-contract.test.mjs
git diff --cached --check
git commit -m "feat: define compact CHRNX header controls"

Task 2: Build one mobile header controller

Files:

  • Modify: blocks/header-tools/block.json

  • Modify: assets/js/navigation.js

  • Delete: assets/js/search.js

  • Modify: tests/js/navigation.test.js

  • Delete: tests/js/search.test.js

  • Step 1: Merge behavior tests and add failing coordination tests

Build one jsdom fixture containing the brand, navigation, search, theme trigger, theme fieldset, and menu trigger. Add focused tests for:

expect(order()).toEqual([ 'brand', 'search', 'theme', 'menu', 'nav' ]);
open('search');
open('theme');
expect(searchInput.hidden).toBe(true);
expect(themePanel.hidden).toBe(false);
open('menu');
expect(themePanel.hidden).toBe(true);
expect(nav.hidden).toBe(false);

Also require:

  • Search opens from an empty submit, focuses the input, and submits non-empty queries without interception.

  • Search synchronizes its button's aria-expanded with controlled-row visibility in every state.

  • Theme and Menu retain trigger focus on open; the next Tab reaches the checked radio or first link through DOM order.

  • Escape closes the active panel and restores its trigger.

  • A pointer/focus move outside Theme closes it without stealing new focus.

  • Reinitialization installs one listener set and cleanup restores original DOM.

  • At 599 → 600 px, Search input moves to Search button; Menu trigger moves to the first navigation link; Theme trigger moves to the checked theme radio; visible nav-link and radio focus remain unchanged.

  • At 600 → 599 px, a focused nav link moves to Menu when nav closes.

  • Tab is never prevented.

  • Step 2: Run Jest and verify RED

Run:

npm run test:js -- --runInBand tests/js/navigation.test.js

Expected: FAIL because the current independent controllers cannot coordinate panels or produce the approved DOM order.

  • Step 3: Implement the central controller

In navigation.js, expose and test initialize() while keeping the browser auto-initializer. Use these internal boundaries:

const PANEL = { search: 'search', theme: 'theme', menu: 'menu' };

function setActivePanel(name, options = {}) { /* one state transition */ }
function applyViewport(matches) { /* mobile order or desktop restore */ }
function restoreOriginalOrder() {
  /* Restore comment anchors, then remove them on cleanup. */
}
function closeForOutsideTarget(target) { /* preserve target focus */ }

Rules:

  • Track one activePanel; state transitions close all other panels without restoring their triggers.
  • Search moves focus to its input; Theme and Menu retain trigger focus.
  • Every state change synchronizes each trigger's aria-expanded and aria-controls target visibility.
  • Escape alone restores the active trigger.
  • Outside pointer/focus closes Theme without calling focus().
  • Store comment anchors before moving elements. Mobile order is Search, Theme, Menu, Navigation. Desktop cleanup restores the server-rendered order.
  • On desktop, Navigation and theme radios are visible, Menu is hidden, and the existing compact search behavior remains unchanged.
  • Never intercept a non-empty native search submit or Tab.
  • Fail closed when any required element or media API is absent.

Remove the header-tools block's search.js metadata ownership, search.js itself, and its standalone test atomically only after the merged tests cover all three original search behaviors.

  • Step 4: Run Jest and verify GREEN

Run:

npm run test:js -- --runInBand tests/js/navigation.test.js \
  tests/js/theme-preference.test.js

Expected: PASS; no duplicate listeners or remote calls.

  • Step 5: Commit controller behavior
git add blocks/header-tools/block.json assets/js/navigation.js \
  assets/js/search.js tests/js/navigation.test.js tests/js/search.test.js
git diff --cached --check
git commit -m "feat: coordinate CHRNX mobile header panels"

Task 3: Implement the approved responsive presentation

Files:

  • Modify: assets/css/layout.css

  • Modify: tests/e2e/navigation.spec.mjs

  • Step 1: Add failing layout assertions

At 375, 599, and 600 px, assert computed geometry rather than class names:

expect(Math.abs(brandBox.y - searchBox.y)).toBeLessThan(4);
expect(Math.abs(searchBox.y - themeBox.y)).toBeLessThan(4);
expect(Math.abs(themeBox.y - menuBox.y)).toBeLessThan(4);
expect(header.scrollWidth).toBeLessThanOrEqual(header.clientWidth);

At 375 and 599 px, require one 68–76 px closed bar; Search, Theme, and Menu targets whose computed width and height each fall within [44, 45] px; unique accessible names in closed and open states; no overlap; and full-width Search/Menu panels below it. Require Theme to appear as an anchored popover that stays inside the viewport. At 600 and 1280 px, capture the existing desktop geometry as an invariant.

  • Step 2: Run focused Chromium E2E and verify RED

Run:

PATH="/opt/homebrew/opt/docker/bin:$PATH" \
  npx playwright test tests/e2e/navigation.spec.mjs \
  --project=chromium --grep "compact mobile header"

Expected: FAIL because the current mobile header wraps into multiple rows.

  • Step 3: Implement mobile-only CSS

Within @media (max-width: 599px):

  • keep .chrnx-site-header__inner on one closed row;
  • let the brand shrink without distorting the SVG;
  • style Search, Theme, and Menu as equal 44–45 px icon buttons;
  • render expanded Search and Menu as full-width rows below the bar;
  • render Theme as a right-aligned, viewport-contained popover;
  • hide closed panels with the native hidden contract;
  • retain visible focus rings and AA colors in both themes;
  • remove nonessential transitions under prefers-reduced-motion.

Do not change tablet or desktop declarations. Keep the no-JavaScript mobile nav and search visible, even if they occupy extra rows.

  • Step 4: Run focused E2E and CSS lint; verify GREEN

Run:

npm run lint:css
PATH="/opt/homebrew/opt/docker/bin:$PATH" \
  npx playwright test tests/e2e/navigation.spec.mjs --project=chromium

Expected: PASS at 375, 599, 600, and 1280 px.

  • Step 5: Commit responsive presentation
git add assets/css/layout.css tests/e2e/navigation.spec.mjs
git diff --cached --check
git commit -m "style: compact the CHRNX mobile header"

Task 4: Prove theme precedence and browser behavior

Files:

  • Modify: tests/e2e/theme-preference.spec.mjs

  • Modify: tests/e2e/navigation.spec.mjs

  • Step 1: Add failing integration scenarios

Cover:

  • saved Light and Dark overriding the OS before and after OS changes;

  • System removing the stored key and following later OS changes;

  • selection and resolved theme surviving reload;

  • Theme popover outside-click and Escape focus behavior;

  • Search → Theme → Menu mutual exclusion;

  • real Tab order without a trap;

  • mobile/desktop resize focus destinations;

  • no-JavaScript system colors, visible navigation, and GET search submission;

  • axe checks with every mobile panel open;

  • no horizontal overflow at all four Task 7 viewports, asserted inside tests/e2e/navigation.spec.mjs without editing the Task 7 visual-state spec.

  • Step 2: Run focused integration tests and verify RED where coverage is new

Run:

PATH="/opt/homebrew/opt/docker/bin:$PATH" \
  npx playwright test tests/e2e/navigation.spec.mjs \
  tests/e2e/theme-preference.spec.mjs \
  --project=chromium

Expected: new assertions fail before their matching behavior is complete.

  • Step 3: Make the smallest controller/CSS corrections

Change only navigation.js, theme-toggle.js, or layout.css where a failing browser assertion proves a real mismatch. Do not change desktop layout or the approved panel design.

  • Step 4: Run the three-browser matrix

Run:

PATH="/opt/homebrew/opt/docker/bin:$PATH" npm test

Expected: PHP, JS, smoke, lint, and Chromium/Firefox/WebKit E2E all pass. Axe remains intentionally Chromium-only where the existing harness requires it.

  • Step 5: Commit integration hardening
git add assets/js/navigation.js assets/js/theme-toggle.js \
  assets/css/layout.css \
  tests/e2e/navigation.spec.mjs tests/e2e/theme-preference.spec.mjs
git diff --cached --check
git commit -m "test: harden CHRNX mobile header behavior"

Task 5: Refresh and approve the real mobile views

Files:

  • Create: scripts/capture-mobile-header-review.mjs

  • Generate, do not commit: tmp/imagegen/home-mobile-dark-v2.png

  • Generate, do not commit: tmp/imagegen/home-mobile-light-v2.png

  • Generate, do not commit: tmp/imagegen/header-mobile-dark-search.png

  • Generate, do not commit: tmp/imagegen/header-mobile-dark-theme.png

  • Generate, do not commit: tmp/imagegen/header-mobile-dark-menu.png

  • Generate, do not commit: tmp/imagegen/header-mobile-light-search.png

  • Generate, do not commit: tmp/imagegen/header-mobile-light-theme.png

  • Generate, do not commit: tmp/imagegen/header-mobile-light-menu.png

  • Step 1: Capture the approved closed and open states

Capture 375 px dark/light closed headers plus Search, Theme, and Menu open states. Bound lazy-image waits as the existing capture script does.

Run:

PATH="/opt/homebrew/opt/docker/bin:$PATH" \
  node scripts/capture-mobile-header-review.mjs

Expected: the eight exact PNG paths listed above exist and decode.

  • Step 2: Inspect screenshots

Verify one closed row, undistorted CHRNX mark, equal targets, popover containment, no text clipping, clear focus, and no content jump. Open the images for the user.

  • Step 3: Commit the isolated capture tool
git add scripts/capture-mobile-header-review.mjs
git diff --cached --check
git diff --cached -- scripts/capture-mobile-header-review.mjs
git commit -m "test: capture CHRNX mobile header states"
  • Step 4: Run final repository checks
PATH="/opt/homebrew/opt/docker/bin:$PATH" npm test
git diff --check
git status --short

Expected: all checks pass. Only intentional Task 7 changes remain uncommitted; header commits contain no fixture, responsive-image, content-seeding, or Task 7 visual-state files. The plan and capture tool are committed separately.

  • Step 5: Request visual approval

Stop before committing any screenshot. Report exact paths and wait for the user's approval. If approved, resume the existing Task 7 integration and its review loop; never push or deploy without a separate request.