docs: design configurable Related Stories layouts
This commit is contained in:
1 file changed
+152
@@ -0,0 +1,152 @@
|
||||
# Related Stories Layouts Design
|
||||
|
||||
**Status:** Proposed for implementation
|
||||
**Date:** 2026-08-12
|
||||
|
||||
## Goal
|
||||
|
||||
Turn `chrnx/related-posts` into a configurable editorial block that displays three or five related stories as an adaptive layout, a fixed grid, or a manual horizontal carousel.
|
||||
|
||||
## Editorial defaults
|
||||
|
||||
- The block defaults to three stories and `adaptive` layout.
|
||||
- Editors may choose only three or five stories. Existing saved values outside that set render as three.
|
||||
- The current topic → shared tags → recency selection algorithm remains unchanged.
|
||||
- If fewer eligible stories exist, the block renders only those stories. It never adds placeholders or duplicates.
|
||||
- The public heading remains “Related stories,” with the existing configurable semantic heading level.
|
||||
|
||||
## Block attributes and editor controls
|
||||
|
||||
`blocks/related-posts/block.json` exposes:
|
||||
|
||||
- `limit`: integer, enum `[3, 5]`, default `3`.
|
||||
- `layout`: string, enum `adaptive`, `grid`, `carousel`, default `adaptive`.
|
||||
- `headingLevel`: existing integer enum `2–6`.
|
||||
|
||||
The block editor adds an inspector panel named “Related stories settings” with:
|
||||
|
||||
- A `SelectControl` named “Stories to show” containing `3` and `5`.
|
||||
- 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.
|
||||
|
||||
The server renderer owns validation. Malformed or legacy attributes fail closed to the defaults. Editor controls cannot be the only validation boundary.
|
||||
|
||||
## Rendered contract
|
||||
|
||||
The existing semantic section and card markup stay intact. The list wrapper changes from the fixed `chrnx-related-posts__grid` contract to:
|
||||
|
||||
```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>
|
||||
<!-- existing semantic article cards -->
|
||||
</div>
|
||||
<div class="chrnx-related-posts__controls" aria-label="Related stories navigation">
|
||||
<button type="button" data-chrnx-related-previous>Previous stories</button>
|
||||
<button type="button" data-chrnx-related-next>Next stories</button>
|
||||
</div>
|
||||
</section>
|
||||
```
|
||||
|
||||
The renderer emits exactly one allowlisted class: `is-layout-adaptive`, `is-layout-grid`, or `is-layout-carousel`.
|
||||
|
||||
- `grid`: controls are not rendered.
|
||||
- `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.
|
||||
|
||||
## Layout behavior
|
||||
|
||||
### Adaptive
|
||||
|
||||
- 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.
|
||||
- At 900px and below, cards become a horizontal rail.
|
||||
|
||||
### Grid
|
||||
|
||||
- Cards always wrap in a grid.
|
||||
- Large screens use up to three columns.
|
||||
- Narrow screens collapse to one column, so no horizontal page overflow is introduced.
|
||||
|
||||
### 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.
|
||||
- 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.
|
||||
|
||||
- Previous and next buttons scroll by one card plus the measured gap.
|
||||
- The script measures live card geometry; it does not hardcode pixel distances.
|
||||
- Buttons use native buttons, retain normal Tab order, and never trap focus.
|
||||
- Buttons become disabled at the corresponding edge. Edge state updates after scrolling, resizing, and initialization.
|
||||
- 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.
|
||||
|
||||
## Accessibility
|
||||
|
||||
- Cards retain DOM and reading order.
|
||||
- Every link and button has a visible focus indicator meeting the existing light/dark focus token contract.
|
||||
- Control targets are at least 45×45 CSS pixels.
|
||||
- Previous/next labels are translated with text domain `chrnx` and provide meaningful accessible names.
|
||||
- Disabled states use the native `disabled` attribute.
|
||||
- No live region announces ordinary scrolling; it would add noise without conveying new content.
|
||||
- At 200% zoom, cards wrap or scroll within the section and do not clip text.
|
||||
- Themes Light, Dark, and System preserve contrast and functionality.
|
||||
|
||||
## Synthetic content and permalinks
|
||||
|
||||
Related Stories must use ordinary `get_permalink()` output from seeded published fixtures. The seed remains local-only and idempotent. Integration tests click a rendered related-card link and require an HTTP 200 single-post destination, preventing the synthetic 404 behavior observed during review.
|
||||
|
||||
This feature does not create production content, alter public permalink settings, or add test-only URL behavior to production rendering.
|
||||
|
||||
## Testing
|
||||
|
||||
Test-driven implementation begins with failing tests for:
|
||||
|
||||
- Exact block attribute enums/defaults and editor script registration.
|
||||
- Server-side sanitization of malformed `limit` and `layout` attributes.
|
||||
- Exact item count for three, five, and fewer-than-requested results.
|
||||
- Layout classes and conditional control markup.
|
||||
- Localized editor labels and frontend controls.
|
||||
- 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.
|
||||
- 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.
|
||||
- Automated accessibility checks on a single-post page containing the block.
|
||||
|
||||
The existing topic/tag/recency query semantics, heading hierarchy, card escaping, empty result behavior, and unrelated block tests must remain green.
|
||||
|
||||
## Files and boundaries
|
||||
|
||||
Expected implementation files:
|
||||
|
||||
- `blocks/related-posts/block.json`
|
||||
- `blocks/related-posts/render.php`
|
||||
- `blocks/related-posts/style.css`
|
||||
- `assets/js/related-posts.js`
|
||||
- `assets/js/editor-related-posts.js`
|
||||
- `inc/editor.php`
|
||||
- `tests/php/BlockRenderingTest.php`
|
||||
- `tests/php/EditorAssetsTest.php`
|
||||
- `tests/js/related-posts.test.js`
|
||||
- `tests/js/editor-related-posts.test.js`
|
||||
- `tests/e2e/related-stories.spec.mjs`
|
||||
- relevant smoke fixture/metadata contracts only if required
|
||||
|
||||
The work stays separate from the character-led section branch. It does not change the related-post selection algorithm, global navigation, footer, theme preference, image generation, or production data.
|
||||
|
||||
## Acceptance
|
||||
|
||||
The design is complete when an editor can select `3` or `5` and `Adaptive`, `Grid`, or `Carousel`; the frontend renders the exact selection accessibly; all stories remain usable without JavaScript; no autoplay or infinite loop exists; seeded links resolve; and the full repository verification passes in the isolated test environment.
|
||||
Reference in new issue
Block a user