fix: preserve progressive CHRNX search

This commit is contained in:
chrnx committed 2026-08-11 19:45:14 -05:00
1 parent 55166c6d2a
commit e7956a1496
7 files changed
+66 -31

No files matched your search

@@ -26,7 +26,8 @@ properties, Jest/jsdom, PHPUnit, Playwright, axe-core, wp-env on Colima.
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`: stop loading the retired search controller.
- `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.
@@ -81,16 +82,18 @@ git commit -m "docs: plan compact CHRNX mobile header"
- Modify: `blocks/theme-toggle/render.php`
- Modify: `blocks/header-tools/render.php`
- Modify: `blocks/header-tools/block.json`
- 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
`aria-expanded="false"`, a controlled search-row ID, and only `navigation.js`
as the shell controller. Preserve native radio and GET form semantics.
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.
```php
$this->assertSame( 1, substr_count( $html, 'data-chrnx-theme-button' ) );
@@ -103,17 +106,29 @@ $this->assertStringContainsString( 'role="search"', $search_html );
$this->assertStringContainsString( 'method="get"', $search_html );
$this->assertMatchesRegularExpression(
'/data-chrnx-search-button[^>]+aria-controls="([^"]+)"' .
'[^>]+aria-expanded="false"/',
'[^>]+aria-expanded="true"/',
$search_html
);
$this->assertStringContainsString( 'data-chrnx-search-panel', $search_html );
```
```js
assert.doesNotMatch(headerToolsMetadata, /search\.js/);
assert.match(headerToolsMetadata, /search\.js/);
assert.match(mobileMenuMetadata, /navigation\.js/);
```
Require the existing search controller to synchronize the enhanced state:
```js
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:
@@ -122,10 +137,11 @@ 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
header-tools block still owns `search.js`.
search button does not yet expose its visible server-rendered state.
- [ ] **Step 3: Implement minimal progressive markup**
@@ -142,9 +158,10 @@ Render a wrapper containing:
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 initialize `aria-expanded="false"`. Keep the native GET form. Remove
`search.js` from `blocks/header-tools/block.json`; `navigation.js` remains
loaded by the mobile menu block.
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**
@@ -156,7 +173,8 @@ Expected: PASS with no PHP warnings or Node test failures.
```bash
git add blocks/theme-toggle/render.php blocks/header-tools/render.php \
blocks/header-tools/block.json tests/php/BlockRenderingTest.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"
@@ -166,6 +184,7 @@ git commit -m "feat: define compact CHRNX header controls"
**Files:**
- Modify: `blocks/header-tools/block.json`
- Modify: `assets/js/navigation.js`
- Delete: `assets/js/search.js`
- Modify: `tests/js/navigation.test.js`
@@ -247,7 +266,8 @@ Rules:
- Never intercept a non-empty native search submit or Tab.
- Fail closed when any required element or media API is absent.
Remove `search.js` and its standalone test only after the merged tests cover all
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**
@@ -264,8 +284,8 @@ Expected: PASS; no duplicate listeners or remote calls.
- [ ] **Step 5: Commit controller behavior**
```bash
git add assets/js/navigation.js assets/js/search.js \
tests/js/navigation.test.js tests/js/search.test.js
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"
```