<traceability-matrix>
Auto-discovers a 2D cross-reference grid (RTM) from page elements; composes data-table for sortable + heatmap-able presentation, adds chain highlight.
Overview
The <traceability-matrix> component renders the canonical Requirements Traceability Matrix (RTM) shape — rows × columns at-a-glance — by auto-discovering source elements on the page. Use it to verify coverage between personas and stories, stories and work items, requirements and tests, or any other cross-cutting relationship in a planning artifact graph.
It composes <data-table> so the rendered grid is sortable and styleable, and adds two things data-table can't: auto-discovery (you give it CSS selectors, not hand-built rows) and chain highlight (activating a cell marks the row and column source elements page-wide so authors can see the connection in surrounding components).
How it works
- Author CSS selectors for the row and column source elements (e.g.
rows='[data-row-kind="story"]',cols='[data-row-kind="persona"]'). - Name the link attribute with
link-attr. The component reads each row element's value(s) and matches them against each column element'sid,story-id(<user-story>) oritem-id(<work-item>). Setmatch-attrto match one specific attribute instead (e.g.match-attr="data-req"). - Comma-separated values are supported out of the box —
data-persona-id="p-sarah,p-jordan"renders two checkmarks. - Orphan flagging — set
flag-orphansto mark empty rows and columns withdata-orphanso CSS can call them out (the default style adds a ⚠ glyph).
Attributes
| Attribute | Values | Default | Description |
|---|---|---|---|
rows | string | — | CSS selector for row source elements |
cols | string | — | CSS selector for column source elements |
link-attr | string | — | Attribute on the row element whose value(s) reference column identifiers (see match-attr); comma-separated values supported |
match-attr | string | — | Attribute on column elements that link-attr values are matched against. Default: the column's id, story-id (<user-story>) or item-id (<work-item>), whichever matches |
label | string | — | Optional heading shown above the matrix |
row-label | string | — | Header cell text for the row axis |
cell-mark | string | — | Glyph shown in linked cells (default: ✓) |
flag-orphans | boolean | — | Mark empty rows/columns with data-orphan for CSS targeting |
Child attributes
| Attribute | On | Values | Description |
|---|---|---|---|
data-matrix-label | * | string | Override the label rendered for this element in matrices that include it |
Events
| Event | Detail | Description |
|---|---|---|
traceability-matrix:ready | { rowCount, colCount, linkCount } | Fired after the matrix renders |
traceability-matrix:highlight | { rowEl, colEl, on } | Fired when a cell toggles chain highlight (click, or Enter/Space on the cell's button) |
Persona × Story example
<traceability-matrix rows='[data-row-kind="story"]' cols='[data-row-kind="persona"]' link-attr="data-persona-id" label="Story coverage" row-label="Story" flag-orphans></traceability-matrix> <!-- elsewhere on the page --><article data-row-kind="persona" id="p-sarah" data-matrix-label="Sarah Chen">…</article><article data-row-kind="persona" id="p-alex" data-matrix-label="Alex Rivera">…</article> <article data-row-kind="story" id="s-1" data-persona-id="p-sarah" data-matrix-label="Weekly digest">…</article><article data-row-kind="story" id="s-2" data-persona-id="p-alex" data-matrix-label="Sprint retro">…</article><article data-row-kind="story" id="s-3" data-persona-id="p-sarah,p-jordan" data-matrix-label="Layout review">…</article>
Story × Work-item example
Pack elements work too — point at <user-story> / <work-item> directly. A work item's story-ids are matched against each story's story-id, so the stories don't need a matching id:
<traceability-matrix rows="work-item" cols="user-story" link-attr="story-ids" label="Work item ↔ story" row-label="Work item"></traceability-matrix> <user-story story-id="US-1">…</user-story><user-story story-id="US-2">…</user-story><work-item item-id="WI-7" story-ids="US-1,US-2">…</work-item><work-item item-id="WI-8" story-ids="US-2">…</work-item>
The matrix uses data-matrix-label on each source if present, else its id, else its trimmed text content.
Chain highlight
Each matrix cell and row header holds a <button>. Clicking it, or pressing Enter / Space while it has focus, toggles data-state-highlighted on:
- the cell itself,
- the matrix row,
- the row source element page-wide,
- the column source element page-wide.
Only one chain is highlighted at a time; rows and columns without an id highlight too. The highlight is cleared from the page when the matrix is removed. The default stylesheet adds an outline to highlighted source elements so authors can scan the page and see the connection. Listen for traceability-matrix:highlight to wire additional behaviour (auto-scroll, side panel, etc.).
document.querySelector('traceability-matrix') .addEventListener('traceability-matrix:highlight', (e) => { const { rowEl, colEl, on } = e.detail; if (on && rowEl) rowEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); });
Accessibility
- Body cells keep
aria-label="linked"/"not linked"and contain a button named “row × column: linked” (or “not linked”), so the relationship is spoken without relying on the ✓ glyph. - Buttons use
aria-pressedto report the active highlight; row-header buttons are named “Highlight row”. - Keyboard (grid pattern). The table has
role="grid"and is a single Tab stop (rovingtabindex): Tab enters at the last cell you used, or the first cell. ← → ↑ ↓ move between cells, including the sortable column headers; Home / End go to the start / end of the row; Ctrl+Home / Ctrl+End to the first / last cell of the matrix. Enter or Space toggles the highlight on a cell (or sorts, on a column header). Rows hidden by filtering are skipped. - Why
role="grid": it follows the WAI-ARIA APG grid pattern, so screen readers switch to focus mode and pass the arrow keys to the matrix instead of using them for reading. The native<tr>/<th>/<td>still map to row, column / row header, and grid cell, so headers are announced as you move. The grid is named by thelabelattribute (or “Traceability matrix”).
Progressive Enhancement
- HTML. Without JS, the matrix host is empty — auto-discovery is inherently runtime. For no-JS RTMs, render a
<data-table>directly with hand-built intersection rows. The matrix component is purely additive. - CSS. The :not(:defined) selector keeps the host visible pre-upgrade.
- JS. Auto-discovers rows/cols, builds the table, wires chain-highlight buttons, fires
traceability-matrix:ready.
Related
<data-table>— Provides the rendered table; inherits all of its sortable/heatmap behaviour.<quadrant-grid>— 2D primitive for 2x2 categorical layouts (different shape than RTM's intersection grid).<user-persona>,<user-story>,<work-item>— common source elements for the matrix.