@ngbracket/a11y-devtools 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to `@ngbracket/a11y-devtools` are documented here.
4
4
  This project adheres to [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## 0.7.0
7
+
8
+ ### Added
9
+
10
+ - **Keyboard & Focus Mode — M2: the accessibility-tree preview.** With
11
+ `keyboard: true` **and** `overlay: true`, a panel now follows focus: as you Tab,
12
+ it shows the focused control's computed **role, accessible name, description, and
13
+ ARIA states**, attributed to the owning component.
14
+ - Name and role are computed by **axe-core's own accname commons** (one accname
15
+ source, not a second home-grown one). axe stays behind a dynamic import, so the
16
+ prod-weight guarantee is unchanged.
17
+ - **Honesty guardrail:** the panel is headed *"Accessibility-tree preview —
18
+ computed approximation"* and never branded as any specific screen reader's
19
+ output. A missing accessible name is flagged in warning colour.
20
+ - New public API: `describeElement` (async, axe-backed), `accessibleDescription`,
21
+ `ariaStates`, and the `AxDescription` / `AxPanelData` types; the overlay gains
22
+ `renderAxPanel`.
23
+
6
24
  ## 0.6.0
7
25
 
8
26
  ### Added
package/README.md CHANGED
@@ -19,8 +19,9 @@ Part of the `@ngbracket` Angular tooling family.
19
19
  Ships attribution — component **and** directive-level — + axe scan + grouped
20
20
  console reporter (with a summary line) + the dev-only provider + the visual in-app
21
21
  overlay (severity-coloured highlights, click-to-scroll) + headless report mode +
22
- **Keyboard & Focus Mode M1** (tab-order visualisation + keyboard-reachability
23
- findings — the part of accessibility axe can't test).
22
+ **Keyboard & Focus Mode M1 + M2** — tab-order visualisation, keyboard-reachability
23
+ findings, and a focus-follow accessibility-tree preview (the part of accessibility
24
+ axe can't test).
24
25
 
25
26
  ## How the attribution works
26
27
 
@@ -183,8 +184,24 @@ npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
183
184
 
184
185
  **Honesty guardrail:** `click-without-key` and `tab-order-mismatch` are
185
186
  *heuristics* — labelled "verify manually", never reported as confirmed failures.
186
- (Next: M2 — an accessibility-tree preview, framed as a *computed approximation*,
187
- never "what a screen reader says".)
187
+
188
+ ### Accessibility-tree preview (M2)
189
+
190
+ With `keyboard: true` **and** `overlay: true`, a panel follows focus: as you Tab, it
191
+ shows the focused control's computed **role, accessible name, description, and ARIA
192
+ states** — attributed to its owning component. The name and role come from
193
+ axe-core's own accessible-name commons (one accname source, shared with the scan),
194
+ and a missing accessible name is flagged in warning colour.
195
+
196
+ > **Accessibility-tree preview — computed approximation.** This is a *computed*
197
+ > name/role/state, an approximation of what assistive tech announces — **not** what
198
+ > any one screen reader says. Real output varies by screen reader (NVDA / JAWS /
199
+ > VoiceOver), browse vs. focus mode, verbosity, and browser. Use it to catch
200
+ > missing names and wrong roles fast; confirm the announcement with a real SR.
201
+
202
+ The same computation is available programmatically via `describeElement(el)`
203
+ (async — it loads axe on demand), plus the pure `ariaStates(el)` and
204
+ `accessibleDescription(el)` helpers.
188
205
 
189
206
  ## What it checks (and what it can't)
190
207
 
@@ -225,9 +242,9 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
225
242
 
226
243
  ## Roadmap
227
244
 
228
- - Keyboard & Focus Mode **M2** — accessibility-tree preview (role + accessible
229
- name + state as you Tab), framed as a *computed approximation*.
230
245
  - Keyboard & Focus Mode **M3** — focus-trap *candidate* detection.
246
+ - Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
247
+ route in report-mode (M2's preview is currently overlay-only).
231
248
  - HTML report + baseline/diff mode for CI.
232
249
  - Per-component filtering and a violation-count badge.
233
250
 
@@ -235,4 +252,5 @@ Done: component attribution (nearest app-owned, walking past UI primitives) ·
235
252
  directive / `hostDirectives` attribution · configurable framework prefixes · axe
236
253
  scan · grouped console reporter · dev-only provider · in-app overlay · headless
237
254
  report mode (CLI + `./report`) · **Keyboard & Focus Mode M1** (tab-order viz +
238
- keyboard-reachability findings) · CI prod-weight guard.
255
+ keyboard-reachability findings) · **M2** (focus-follow accessibility-tree preview) ·
256
+ CI prod-weight guard.
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { logFindings, type Logger } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, type NgDebugGlobal, type NgListener, } from './attribution.js';
6
6
  export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard, type KeyboardScanOptions } from './keyboard/keyboard-scan.js';
8
- export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, } from './overlay.js';
8
+ export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
9
+ export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, type AxPanelData, } from './overlay.js';
package/dist/index.js CHANGED
@@ -5,4 +5,5 @@ export { logFindings } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, } from './attribution.js';
6
6
  export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard } from './keyboard/keyboard-scan.js';
8
+ export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
8
9
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
@@ -34268,6 +34268,24 @@
34268
34268
  connector.setAttribute("opacity", "0.7");
34269
34269
  svg.appendChild(connector);
34270
34270
  container.appendChild(svg);
34271
+ const axPanel = doc.createElement("div");
34272
+ axPanel.setAttribute(OVERLAY_ATTR, "");
34273
+ Object.assign(axPanel.style, {
34274
+ position: "fixed",
34275
+ right: "12px",
34276
+ bottom: "12px",
34277
+ maxWidth: "320px",
34278
+ padding: "8px 10px",
34279
+ borderRadius: "6px",
34280
+ background: "rgba(20,22,28,0.94)",
34281
+ color: "#f4f4f5",
34282
+ font: "12px/1.5 ui-sans-serif, system-ui, sans-serif",
34283
+ boxShadow: "0 2px 12px rgba(0,0,0,0.4)",
34284
+ pointerEvents: "none",
34285
+ zIndex: "2147483647",
34286
+ display: "none"
34287
+ });
34288
+ container.appendChild(axPanel);
34271
34289
  let highlights = [];
34272
34290
  let tabBadges = [];
34273
34291
  const reposition = () => {
@@ -34340,14 +34358,60 @@
34340
34358
  }
34341
34359
  repositionTabOrder();
34342
34360
  }
34361
+ function renderAxPanel(data) {
34362
+ if (!data) {
34363
+ axPanel.style.display = "none";
34364
+ axPanel.replaceChildren();
34365
+ return;
34366
+ }
34367
+ axPanel.replaceChildren(...buildAxPanelContent(doc, data));
34368
+ axPanel.style.display = "block";
34369
+ }
34343
34370
  function destroy() {
34344
34371
  clear();
34345
34372
  clearTabOrder();
34373
+ renderAxPanel(null);
34346
34374
  win?.removeEventListener("scroll", onViewportChange, { capture: true });
34347
34375
  win?.removeEventListener("resize", onViewportChange);
34348
34376
  container.remove();
34349
34377
  }
34350
- return { render, renderTabOrder, clear, clearTabOrder, destroy };
34378
+ return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
34379
+ }
34380
+ function buildAxPanelContent(doc, data) {
34381
+ const nodes = [];
34382
+ const header = doc.createElement("div");
34383
+ header.textContent = "Accessibility-tree preview \u2014 computed approximation";
34384
+ Object.assign(header.style, {
34385
+ fontWeight: "700",
34386
+ fontSize: "10px",
34387
+ letterSpacing: "0.02em",
34388
+ textTransform: "uppercase",
34389
+ color: "#a9b0bd",
34390
+ marginBottom: "4px"
34391
+ });
34392
+ header.title = "A computed name/role/state \u2014 an approximation of what assistive tech announces, not any one screen reader.";
34393
+ nodes.push(header);
34394
+ const row = (label, value, muted = false) => {
34395
+ const div = doc.createElement("div");
34396
+ const key = doc.createElement("span");
34397
+ key.textContent = `${label}: `;
34398
+ key.style.color = "#a9b0bd";
34399
+ const val = doc.createElement("span");
34400
+ val.textContent = value;
34401
+ if (muted)
34402
+ val.style.color = "#e8710a";
34403
+ div.append(key, val);
34404
+ return div;
34405
+ };
34406
+ nodes.push(row("role", data.role ?? `(none \u2014 <${data.tag}>)`));
34407
+ nodes.push(data.name ? row("name", `"${data.name}"`) : row("name", "(no accessible name)", true));
34408
+ if (data.description)
34409
+ nodes.push(row("description", `"${data.description}"`));
34410
+ if (data.states.length)
34411
+ nodes.push(row("states", data.states.join(", ")));
34412
+ if (data.component)
34413
+ nodes.push(row("component", data.component));
34414
+ return nodes;
34351
34415
  }
34352
34416
  function buildBadge(doc, stop) {
34353
34417
  const color = stop.positive ? TAB_ORDER_WARN_COLOR : TAB_ORDER_COLOR;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The keyboard layer, part C: a *computed approximation* of what assistive tech
3
+ * would announce for an element — its role, accessible name, description, and
4
+ * ARIA states.
5
+ *
6
+ * HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
7
+ * "what a screen reader says". Real output varies by screen reader
8
+ * (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
9
+ * must label it as such and must not brand it as any specific SR's output.
10
+ *
11
+ * The name and role come from **axe-core's own accessible-name commons** — the
12
+ * same well-tested implementation the scan already relies on — so there's one
13
+ * accname source, not a second home-grown one. axe is loaded via dynamic import
14
+ * (and only when this runs), so it never enters a consumer's static bundle; the
15
+ * prod-weight guard still holds.
16
+ */
17
+ /** A computed approximation of an element's accessibility-tree node. */
18
+ export interface AxDescription {
19
+ /** Computed ARIA role, or null when axe can't resolve one. */
20
+ role: string | null;
21
+ /** Computed accessible name (may be empty — itself a finding worth noticing). */
22
+ name: string;
23
+ /** Computed accessible description (aria-describedby / title), or ''. */
24
+ description: string;
25
+ /** Compact human labels for the element's states, e.g. `['expanded', 'level 2']`. */
26
+ states: string[];
27
+ }
28
+ /**
29
+ * Compute the accessibility-tree approximation for `element`. Resolves to sane
30
+ * defaults (no role, empty name) rather than throwing if axe's tree can't be
31
+ * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
32
+ */
33
+ export declare function describeElement(element: Element): Promise<AxDescription>;
34
+ /** The accessible description: `aria-describedby` targets' text, else the `title`. */
35
+ export declare function accessibleDescription(element: Element): string;
36
+ /**
37
+ * Compact, human-readable state labels — the states a screen reader would voice
38
+ * alongside role and name (expanded, checked, disabled, current, level, position
39
+ * in set). ARIA attributes take precedence, with native fallbacks (a real
40
+ * checkbox's `checked`, a disabled control, a heading's level).
41
+ */
42
+ export declare function ariaStates(element: Element): string[];
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The keyboard layer, part C: a *computed approximation* of what assistive tech
3
+ * would announce for an element — its role, accessible name, description, and
4
+ * ARIA states.
5
+ *
6
+ * HONESTY GUARDRAIL (non-negotiable): this is a computed approximation, NEVER
7
+ * "what a screen reader says". Real output varies by screen reader
8
+ * (NVDA/JAWS/VoiceOver), browse vs. focus mode, verbosity, and browser. Callers
9
+ * must label it as such and must not brand it as any specific SR's output.
10
+ *
11
+ * The name and role come from **axe-core's own accessible-name commons** — the
12
+ * same well-tested implementation the scan already relies on — so there's one
13
+ * accname source, not a second home-grown one. axe is loaded via dynamic import
14
+ * (and only when this runs), so it never enters a consumer's static bundle; the
15
+ * prod-weight guard still holds.
16
+ */
17
+ // axe is a heavy dynamic import; load it once and reuse. Typed loosely because
18
+ // the accname commons used here aren't part of axe's published type surface.
19
+ let axePromise;
20
+ function loadAxe() {
21
+ return (axePromise ??= import('axe-core').then((m) => (m.default ?? m)));
22
+ }
23
+ /**
24
+ * Compute the accessibility-tree approximation for `element`. Resolves to sane
25
+ * defaults (no role, empty name) rather than throwing if axe's tree can't be
26
+ * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
27
+ */
28
+ export async function describeElement(element) {
29
+ const axe = await loadAxe();
30
+ const doc = element.ownerDocument ?? document;
31
+ let role = null;
32
+ let name = '';
33
+ try {
34
+ axe.setup(doc);
35
+ const vnode = axe.utils.getNodeFromTree(element);
36
+ role = axe.commons.aria.getRole(element) ?? null;
37
+ name = vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '';
38
+ }
39
+ catch {
40
+ // Leave role=null / name='' — axe couldn't build a tree (e.g. run in flight).
41
+ }
42
+ finally {
43
+ try {
44
+ axe.teardown();
45
+ }
46
+ catch {
47
+ /* nothing set up */
48
+ }
49
+ }
50
+ return { role, name, description: accessibleDescription(element), states: ariaStates(element) };
51
+ }
52
+ /** The accessible description: `aria-describedby` targets' text, else the `title`. */
53
+ export function accessibleDescription(element) {
54
+ const ids = element.getAttribute('aria-describedby');
55
+ if (ids) {
56
+ const doc = element.ownerDocument ?? document;
57
+ const text = ids
58
+ .split(/\s+/)
59
+ .filter(Boolean)
60
+ .map((id) => doc.getElementById(id)?.textContent?.trim() ?? '')
61
+ .filter(Boolean)
62
+ .join(' ');
63
+ if (text)
64
+ return text;
65
+ }
66
+ return element.getAttribute('title')?.trim() ?? '';
67
+ }
68
+ /** True for an ARIA attribute value that expresses "on" rather than "off"/absent. */
69
+ function isOn(value) {
70
+ return value !== null && value !== 'false' && value !== 'undefined';
71
+ }
72
+ /**
73
+ * Compact, human-readable state labels — the states a screen reader would voice
74
+ * alongside role and name (expanded, checked, disabled, current, level, position
75
+ * in set). ARIA attributes take precedence, with native fallbacks (a real
76
+ * checkbox's `checked`, a disabled control, a heading's level).
77
+ */
78
+ export function ariaStates(element) {
79
+ const states = [];
80
+ const attr = (name) => element.getAttribute(name);
81
+ const expanded = attr('aria-expanded');
82
+ if (expanded === 'true')
83
+ states.push('expanded');
84
+ else if (expanded === 'false')
85
+ states.push('collapsed');
86
+ const checked = attr('aria-checked');
87
+ if (checked === 'true')
88
+ states.push('checked');
89
+ else if (checked === 'false')
90
+ states.push('not checked');
91
+ else if (checked === 'mixed')
92
+ states.push('mixed');
93
+ else if ('checked' in element && element.checked)
94
+ states.push('checked');
95
+ const pressed = attr('aria-pressed');
96
+ if (pressed === 'true')
97
+ states.push('pressed');
98
+ else if (pressed === 'false')
99
+ states.push('not pressed');
100
+ if (attr('aria-selected') === 'true')
101
+ states.push('selected');
102
+ if (isOn(attr('aria-disabled')) || ('disabled' in element && element.disabled)) {
103
+ states.push('disabled');
104
+ }
105
+ if (isOn(attr('aria-required')) || ('required' in element && element.required)) {
106
+ states.push('required');
107
+ }
108
+ if (attr('aria-invalid') === 'true')
109
+ states.push('invalid');
110
+ if (attr('aria-readonly') === 'true')
111
+ states.push('read only');
112
+ const current = attr('aria-current');
113
+ if (isOn(current))
114
+ states.push(current === 'true' ? 'current' : `current ${current}`);
115
+ const haspopup = attr('aria-haspopup');
116
+ if (isOn(haspopup))
117
+ states.push(haspopup === 'true' ? 'has popup' : `has ${haspopup} popup`);
118
+ const level = attr('aria-level') ?? headingLevel(element);
119
+ if (level)
120
+ states.push(`level ${level}`);
121
+ const posinset = attr('aria-posinset');
122
+ const setsize = attr('aria-setsize');
123
+ if (posinset && setsize)
124
+ states.push(`${posinset} of ${setsize}`);
125
+ return states;
126
+ }
127
+ /** The heading level for a native `h1`–`h6`, else null. */
128
+ function headingLevel(element) {
129
+ const match = /^h([1-6])$/.exec(element.tagName.toLowerCase());
130
+ return match ? match[1] : null;
131
+ }
package/dist/overlay.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { A11yFinding } from './scan.js';
2
2
  import type { TabStop } from './keyboard/tab-sequence.js';
3
+ import type { AxDescription } from './keyboard/accname.js';
3
4
  /**
4
5
  * Attribute marking the overlay's own DOM. `scan()` excludes anything under it
5
6
  * so the tool never reports violations against its own highlights.
@@ -7,6 +8,13 @@ import type { TabStop } from './keyboard/tab-sequence.js';
7
8
  export declare const OVERLAY_ATTR = "data-ngb-a11y-overlay";
8
9
  /** Selector form of {@link OVERLAY_ATTR}, passed to axe as an exclude. */
9
10
  export declare const OVERLAY_EXCLUDE_SELECTOR = "[data-ngb-a11y-overlay]";
11
+ /** The computed accessibility-tree info shown in the focus-follow panel. */
12
+ export interface AxPanelData extends AxDescription {
13
+ /** Owning component of the focused element, or null. */
14
+ component: string | null;
15
+ /** Tag name of the focused element, for context (e.g. `div`, `button`). */
16
+ tag: string;
17
+ }
10
18
  export interface A11yOverlay {
11
19
  /** Draw a highlight over each finding's node, replacing the previous set. */
12
20
  render(findings: A11yFinding[]): void;
@@ -15,6 +23,12 @@ export interface A11yOverlay {
15
23
  * independent of the findings highlights. Replaces the previous tab-order set.
16
24
  */
17
25
  renderTabOrder(stops: TabStop[]): void;
26
+ /**
27
+ * Show the accessibility-tree preview panel for the focused element, or hide it
28
+ * when passed `null`. Deliberately framed as a *computed approximation* — see
29
+ * the panel header — never as verbatim screen-reader output.
30
+ */
31
+ renderAxPanel(data: AxPanelData | null): void;
18
32
  /** Remove all highlights but keep the overlay live. */
19
33
  clear(): void;
20
34
  /** Remove the tab-order layer but keep the overlay live. */
package/dist/overlay.js CHANGED
@@ -59,6 +59,27 @@ export function createOverlay(options = {}) {
59
59
  connector.setAttribute('opacity', '0.7');
60
60
  svg.appendChild(connector);
61
61
  container.appendChild(svg); // under the badges, which are appended later
62
+ // The accessibility-tree preview panel: a fixed card that follows focus. Hidden
63
+ // until renderAxPanel is called with data. Marked with OVERLAY_ATTR so scans
64
+ // never flag the tool's own UI.
65
+ const axPanel = doc.createElement('div');
66
+ axPanel.setAttribute(OVERLAY_ATTR, '');
67
+ Object.assign(axPanel.style, {
68
+ position: 'fixed',
69
+ right: '12px',
70
+ bottom: '12px',
71
+ maxWidth: '320px',
72
+ padding: '8px 10px',
73
+ borderRadius: '6px',
74
+ background: 'rgba(20,22,28,0.94)',
75
+ color: '#f4f4f5',
76
+ font: '12px/1.5 ui-sans-serif, system-ui, sans-serif',
77
+ boxShadow: '0 2px 12px rgba(0,0,0,0.4)',
78
+ pointerEvents: 'none',
79
+ zIndex: '2147483647',
80
+ display: 'none',
81
+ });
82
+ container.appendChild(axPanel);
62
83
  let highlights = [];
63
84
  let tabBadges = [];
64
85
  const reposition = () => {
@@ -132,14 +153,63 @@ export function createOverlay(options = {}) {
132
153
  }
133
154
  repositionTabOrder();
134
155
  }
156
+ function renderAxPanel(data) {
157
+ if (!data) {
158
+ axPanel.style.display = 'none';
159
+ axPanel.replaceChildren();
160
+ return;
161
+ }
162
+ axPanel.replaceChildren(...buildAxPanelContent(doc, data));
163
+ axPanel.style.display = 'block';
164
+ }
135
165
  function destroy() {
136
166
  clear();
137
167
  clearTabOrder();
168
+ renderAxPanel(null);
138
169
  win?.removeEventListener('scroll', onViewportChange, { capture: true });
139
170
  win?.removeEventListener('resize', onViewportChange);
140
171
  container.remove();
141
172
  }
142
- return { render, renderTabOrder, clear, clearTabOrder, destroy };
173
+ return { render, renderTabOrder, renderAxPanel, clear, clearTabOrder, destroy };
174
+ }
175
+ /** The rows of the accessibility-tree preview panel, honesty header first. */
176
+ function buildAxPanelContent(doc, data) {
177
+ const nodes = [];
178
+ const header = doc.createElement('div');
179
+ header.textContent = 'Accessibility-tree preview — computed approximation';
180
+ Object.assign(header.style, {
181
+ fontWeight: '700',
182
+ fontSize: '10px',
183
+ letterSpacing: '0.02em',
184
+ textTransform: 'uppercase',
185
+ color: '#a9b0bd',
186
+ marginBottom: '4px',
187
+ });
188
+ header.title = 'A computed name/role/state — an approximation of what assistive tech announces, not any one screen reader.';
189
+ nodes.push(header);
190
+ const row = (label, value, muted = false) => {
191
+ const div = doc.createElement('div');
192
+ const key = doc.createElement('span');
193
+ key.textContent = `${label}: `;
194
+ key.style.color = '#a9b0bd';
195
+ const val = doc.createElement('span');
196
+ val.textContent = value;
197
+ if (muted)
198
+ val.style.color = '#e8710a'; // draw the eye to a missing name
199
+ div.append(key, val);
200
+ return div;
201
+ };
202
+ nodes.push(row('role', data.role ?? `(none — <${data.tag}>)`));
203
+ nodes.push(data.name
204
+ ? row('name', `"${data.name}"`)
205
+ : row('name', '(no accessible name)', true));
206
+ if (data.description)
207
+ nodes.push(row('description', `"${data.description}"`));
208
+ if (data.states.length)
209
+ nodes.push(row('states', data.states.join(', ')));
210
+ if (data.component)
211
+ nodes.push(row('component', data.component));
212
+ return nodes;
143
213
  }
144
214
  /**
145
215
  * A numbered badge marking one tab stop, anchored at the target's top-left
package/dist/provider.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ApplicationRef, DestroyRef, inject, isDevMode, makeEnvironmentProviders, provideEnvironmentInitializer, } from '@angular/core';
2
2
  import { debounceTime, filter } from 'rxjs';
3
3
  import { runA11yScan } from './runner.js';
4
- import { createOverlay } from './overlay.js';
4
+ import { createOverlay, OVERLAY_ATTR } from './overlay.js';
5
5
  import { tabSequence } from './keyboard/tab-sequence.js';
6
+ import { describeElement } from './keyboard/accname.js';
7
+ import { resolveOwningComponentName } from './attribution.js';
6
8
  /**
7
9
  * Dev-only in-app accessibility auditing. Rescans whenever the application
8
10
  * settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
@@ -25,6 +27,26 @@ export function provideA11yDevtools(options = {}) {
25
27
  const appRef = inject(ApplicationRef);
26
28
  const destroyRef = inject(DestroyRef);
27
29
  const overlayView = overlay ? createOverlay() : undefined;
30
+ // Keyboard & Focus Mode, part C: a focus-follow accessibility-tree preview.
31
+ // As the user Tabs, show the focused control's computed role/name/state —
32
+ // the ~2/3 axe can't test — attributed to its component. Only meaningful
33
+ // with the visual overlay on.
34
+ let onFocusIn;
35
+ if (overlayView && keyboard) {
36
+ onFocusIn = (event) => {
37
+ const el = event.target;
38
+ if (!(el instanceof Element) || el.closest(`[${OVERLAY_ATTR}]`))
39
+ return; // skip our own UI
40
+ describeElement(el)
41
+ .then((desc) => overlayView.renderAxPanel({
42
+ ...desc,
43
+ component: resolveOwningComponentName(el, frameworkPrefixes),
44
+ tag: el.tagName.toLowerCase(),
45
+ }))
46
+ .catch(() => undefined);
47
+ };
48
+ document.addEventListener('focusin', onFocusIn, true);
49
+ }
28
50
  let scanning = false;
29
51
  const subscription = appRef.isStable
30
52
  .pipe(filter((stable) => stable), debounceTime(debounceMs))
@@ -48,6 +70,8 @@ export function provideA11yDevtools(options = {}) {
48
70
  });
49
71
  destroyRef.onDestroy(() => {
50
72
  subscription.unsubscribe();
73
+ if (onFocusIn)
74
+ document.removeEventListener('focusin', onFocusIn, true);
51
75
  overlayView?.destroy();
52
76
  });
53
77
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Dev-only in-app accessibility auditing for Angular that maps each axe violation back to the component that rendered it — the attribution React overlay tools can't do.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",