docs: clarify Related Stories progressive enhancement
This commit is contained in:
1 file changed
+18
-9
@@ -29,6 +29,10 @@ The block editor adds an inspector panel named “Related stories settings” wi
|
||||
- A `SelectControl` named “Layout” containing “Adaptive,” “Grid,” and “Carousel.”
|
||||
- Short help text: adaptive uses a grid on larger screens and horizontal scrolling on smaller screens.
|
||||
|
||||
`SelectControl` returns strings. Its `limit` handler strictly allowlists the incoming value and persists an integer: `setAttributes({ limit: Number(value) === 5 ? 5 : 3 })`. Tests prove the saved attribute is numeric `5`, never string `"5"`.
|
||||
|
||||
The block metadata declares `editorScript: file:../../assets/js/editor-related-posts.js`. Its adjacent asset metadata declares the WordPress dependencies used by a narrowly scoped `editor.BlockEdit` wrapper. This makes the controls available both in the post editor and in the Site Editor, where the Single template owns the default block instance; it does not rely on the post-only enqueue guard in `inc/editor.php`.
|
||||
|
||||
The server renderer owns validation. Malformed or legacy attributes fail closed to the defaults. Editor controls cannot be the only validation boundary.
|
||||
|
||||
## Rendered contract
|
||||
@@ -38,10 +42,10 @@ The existing semantic section and card markup stay intact. The list wrapper chan
|
||||
```html
|
||||
<section class="wp-block-chrnx-related-posts chrnx-related-posts is-layout-adaptive" aria-labelledby="…">
|
||||
<h2 id="…">Related stories</h2>
|
||||
<div class="chrnx-related-posts__items" data-chrnx-related-track>
|
||||
<div class="chrnx-related-posts__items" data-chrnx-related-track role="region" aria-labelledby="…" tabindex="0">
|
||||
<!-- existing semantic article cards -->
|
||||
</div>
|
||||
<div class="chrnx-related-posts__controls" aria-label="Related stories navigation">
|
||||
<div class="chrnx-related-posts__controls" role="group" aria-label="Related stories navigation" hidden>
|
||||
<button type="button" data-chrnx-related-previous>Previous stories</button>
|
||||
<button type="button" data-chrnx-related-next>Next stories</button>
|
||||
</div>
|
||||
@@ -54,7 +58,8 @@ The renderer emits exactly one allowlisted class: `is-layout-adaptive`, `is-layo
|
||||
- `adaptive`: controls are rendered for the mobile carousel enhancement and hidden at the desktop grid breakpoint.
|
||||
- `carousel`: controls are rendered at every viewport.
|
||||
- With JavaScript disabled, every story remains reachable in source order through native horizontal scrolling. Buttons are enhancement controls, never the only navigation method.
|
||||
- The list wrapper receives a localized accessible label through its section heading; cards remain articles containing one full-card link.
|
||||
- Carousel-capable tracks are keyboard-focusable regions whose `aria-labelledby` points to the visible section heading. Grid tracks have neither `role="region"` nor `tabindex`. The controls use `role="group"` and the localized accessible name “Related stories navigation.” Cards remain articles containing one full-card link.
|
||||
- The frontend controller removes the adaptive track's region role and tab stop while it is a non-scrollable desktop grid, then restores them when it crosses into the mobile rail. The explicit carousel retains both at every width.
|
||||
|
||||
## Layout behavior
|
||||
|
||||
@@ -62,7 +67,7 @@ The renderer emits exactly one allowlisted class: `is-layout-adaptive`, `is-layo
|
||||
|
||||
- At widths above 900px, cards form a grid.
|
||||
- Three stories use three equal columns.
|
||||
- Five stories use a responsive grid that produces three columns followed by two balanced cards rather than five narrow columns.
|
||||
- Five stories use three equal-width columns and wrap naturally as `3 + 2`; four available stories wrap as `3 + 1`, two as two columns, and one as one column. Empty columns are never rendered.
|
||||
- At 900px and below, cards become a horizontal rail.
|
||||
|
||||
### Grid
|
||||
@@ -74,13 +79,14 @@ The renderer emits exactly one allowlisted class: `is-layout-adaptive`, `is-layo
|
||||
### Carousel
|
||||
|
||||
- Cards stay in a horizontal rail at every width.
|
||||
- Desktop cards expose roughly three cards within the content width; mobile exposes one card plus a small preview of the next card.
|
||||
- Above 900px, each card is `(track width - 2 × computed gap) / 3`, within two CSS pixels, so three cards are visible.
|
||||
- At 900px and below, each card occupies 82% of the track width, capped at 20rem. When another card exists, at least 24 CSS pixels and no more than 25% of it remain visible as a continuation cue.
|
||||
- The rail uses `overflow-x: auto`, `scroll-snap-type: x mandatory`, and source-order cards with `scroll-snap-align: start`.
|
||||
- The page itself never gains horizontal overflow.
|
||||
|
||||
## Controls and progressive enhancement
|
||||
|
||||
A dedicated `assets/js/related-posts.js` controller enhances every rendered carousel independently.
|
||||
A dedicated `assets/js/related-posts.js` controller enhances every rendered carousel independently. `blocks/related-posts/block.json` declares it as `viewScript: file:../../assets/js/related-posts.js`; WordPress therefore registers the local asset with the block and prints it only when the block renders.
|
||||
|
||||
- Previous and next buttons scroll by one card plus the measured gap.
|
||||
- The script measures live card geometry; it does not hardcode pixel distances.
|
||||
@@ -89,7 +95,8 @@ A dedicated `assets/js/related-posts.js` controller enhances every rendered caro
|
||||
- A pointer, trackpad, touch gesture, keyboard scrolling, or button press reaches the same rail.
|
||||
- The script does not autoplay, loop, clone cards, modify card links, export globals, or make network requests.
|
||||
- Missing markup, zero cards, unsupported browser APIs, or a reduced-motion preference fail safely. Reduced motion changes programmatic scrolling from smooth to instant without changing layout or content.
|
||||
- When JavaScript is unavailable, controls are hidden by the existing `.no-js` root class; native scrolling remains available.
|
||||
- Controls carry the native `hidden` attribute in server output. Each controller removes it only after its track, cards, buttons, media query, and scroll APIs initialize successfully. With JavaScript disabled or controller initialization rejected, controls stay hidden and native scrolling remains available.
|
||||
- If a viewport change turns an adaptive rail into a grid, the controller hides controls, removes the track's region/tab-stop enhancement, and leaves focus on a visible control before hiding when necessary. Crossing back restores rail semantics and control state.
|
||||
|
||||
## Accessibility
|
||||
|
||||
@@ -120,7 +127,9 @@ Test-driven implementation begins with failing tests for:
|
||||
- Editor `SelectControl` updates for both attributes.
|
||||
- Independent JavaScript controllers, measured one-card movement, edge disabling, resize updates, reduced motion, missing-markup safety, and cleanup.
|
||||
- CSS contracts for adaptive, grid, carousel, scroll snap, 45px controls, no-JS, reduced motion, and absence of page overflow.
|
||||
- Playwright coverage at 375, 768, 1440, and 2560 pixels in light and dark themes.
|
||||
- Playwright coverage at 375, 768, 900, 901, 1440, and 2560 pixels in light and dark themes.
|
||||
- The complete `3/5 × adaptive/grid/carousel` matrix, plus adaptive availability counts of one, two, and four.
|
||||
- Runtime geometry: exact grid column counts; carousel card width tolerances above; continuation preview bounds; correct control visibility at 900/901; track-only overflow; and `document.documentElement.scrollWidth <= document.documentElement.clientWidth`.
|
||||
- Real pointer/button and keyboard interaction without a focus trap.
|
||||
- No-JS access to every related story.
|
||||
- Clicking a seeded related story returns HTTP 200 rather than 404.
|
||||
@@ -137,7 +146,7 @@ Expected implementation files:
|
||||
- `blocks/related-posts/style.css`
|
||||
- `assets/js/related-posts.js`
|
||||
- `assets/js/editor-related-posts.js`
|
||||
- `inc/editor.php`
|
||||
- `assets/js/editor-related-posts.asset.php`
|
||||
- `tests/php/BlockRenderingTest.php`
|
||||
- `tests/php/EditorAssetsTest.php`
|
||||
- `tests/js/related-posts.test.js`
|
||||
|
||||
Reference in new issue
Block a user