@ngbracket/a11y-devtools 0.4.0 → 0.6.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,50 @@
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.6.0
7
+
8
+ ### Added
9
+
10
+ - **Keyboard & Focus Mode — M1: the keyboard layer.** The first checks for the
11
+ ~2/3 of accessibility axe can't test — keyboard operability — attributed to the
12
+ owning component like everything else. Opt in with `keyboard: true` (provider /
13
+ `runA11yScan` / `scan` / `scanPages`) or `--keyboard` on the CLI.
14
+ - **Tab-order visualisation** (overlay): numbered badges at each tab stop plus a
15
+ connector path showing the order focus actually moves; a positive-`tabindex`
16
+ stop is flagged as a warning because it hijacks the natural order.
17
+ - **Keyboard findings** (`ngbr/*` rule ids, grouped and reported like axe
18
+ violations):
19
+ - `ngbr/unreachable-control` (serious) — an interactive element (ARIA role or a
20
+ runtime `click` listener) that isn't a native control and has no
21
+ `tabindex >= 0`, so it can't be reached by keyboard.
22
+ - `ngbr/click-without-key` (moderate, heuristic) — a focusable element with a
23
+ `(click)` handler but no keyboard handler, so Enter/Space may not activate it.
24
+ Read from `window.ng.getListeners`, a **runtime** signal a static template
25
+ lint can't see (e.g. a listener added via `hostDirectives`).
26
+ - `ngbr/tab-order-mismatch` (moderate, heuristic) — the tab path jumps against
27
+ the visual reading order. Needs real layout (report-mode / a real browser).
28
+ - New public API: `tabSequence`, `scanKeyboard`, `isTabbable`,
29
+ `isNativelyFocusable`, `resolvedTabIndex`, `visualOrderJumps`,
30
+ `resolveListenerEvents`, and the `TabStop` / `NgListener` types.
31
+ - **Honesty guardrail:** the heuristic findings are labelled "verify manually",
32
+ never reported as confirmed failures.
33
+
34
+ ## 0.5.0
35
+
36
+ ### Added
37
+
38
+ - **Configurable framework prefixes.** The component-name prefixes attribution
39
+ walks past (third-party UI primitives) are now configurable instead of a
40
+ hardcoded `Nb`/`Mat`/`Cdk`/`Mdc` list:
41
+ - `provideA11yDevtools({ frameworkPrefixes })`, `runA11yScan(root, { frameworkPrefixes })`,
42
+ `scan(root, axe, { frameworkPrefixes })`, and `scanPages({ frameworkPrefixes })`.
43
+ - CLI: `--framework-prefixes Nb,Mat,Nz,Clr,Ion` and `--no-skip-primitives`.
44
+ - Pass `[]` (or `--no-skip-primitives`) to attribute to the **immediate** owner —
45
+ e.g. when scanning a component library's *own* code, so it blames the library
46
+ component rather than a demo wrapper.
47
+ - Exported `DEFAULT_FRAMEWORK_PREFIXES` (spread it to extend: `[...DEFAULT_FRAMEWORK_PREFIXES, 'Nz']`)
48
+ and the `ScanOptions` type.
49
+
6
50
  ## 0.4.0
7
51
 
8
52
  ### Added
package/README.md CHANGED
@@ -18,7 +18,9 @@ Part of the `@ngbracket` Angular tooling family.
18
18
 
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
- overlay (severity-coloured highlights, click-to-scroll).
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
24
 
23
25
  ## How the attribution works
24
26
 
@@ -62,9 +64,19 @@ provideA11yDevtools({
62
64
  overlay: true, // in-app visual highlights over flagged nodes; default false
63
65
  debounceMs: 500, // quiet window after stabilization before scanning
64
66
  tags: ['wcag22aa'], // scope the ruleset; default = axe-core's full ruleset
67
+ frameworkPrefixes: ['Nb', 'Mat', 'Cdk', 'Mdc'], // UI primitives to attribute past (default)
68
+ keyboard: true, // also run the keyboard layer (see below); default false
65
69
  });
66
70
  ```
67
71
 
72
+ **Framework prefixes.** Attribution walks *past* third-party UI primitives to the app
73
+ component that placed them — a `<button nbButton>` with no name is blamed on your
74
+ `HeaderComponent`, not `NbButtonComponent`. The default list is `Nb`/`Mat`/`Cdk`/`Mdc`;
75
+ override `frameworkPrefixes` to add others (e.g. `['Nb','Mat','Nz','Clr','Ion']` — spread
76
+ `DEFAULT_FRAMEWORK_PREFIXES` to extend), or pass `[]` to attribute to the **immediate**
77
+ owner (useful when auditing a component library's *own* code). The same option is available
78
+ on `scan`, `runA11yScan`, `scanPages`, and the CLI (`--framework-prefixes` / `--no-skip-primitives`).
79
+
68
80
  Findings are grouped by owning component, led by a summary line, and each node's
69
81
  directives are shown inline:
70
82
 
@@ -143,6 +155,37 @@ owning component. When a flagged control is itself a third-party UI primitive
143
155
  (e.g. `<button nbButton>`), attribution walks past the primitive to the app
144
156
  component that placed it and notes the primitive as `(via …)`.
145
157
 
158
+ ## Keyboard & Focus Mode (the ~2/3 axe can't test)
159
+
160
+ axe covers the machine-testable third of WCAG. **Keyboard & Focus Mode** starts on
161
+ the rest — keyboard operability — still naming the component that owns each issue.
162
+ Turn it on with `keyboard: true` (provider / `runA11yScan` / `scan` / `scanPages`)
163
+ or `--keyboard` on the CLI. It adds:
164
+
165
+ - **Tab-order visualisation** (overlay): numbered badges at each tab stop and a
166
+ connector path showing the order focus actually moves. A positive-`tabindex` stop
167
+ is coloured as a warning, because it hijacks the natural order.
168
+ - **Keyboard findings**, grouped and reported exactly like the axe violations:
169
+ - `ngbr/unreachable-control` — an interactive element (an ARIA role, or a runtime
170
+ `click` listener) that isn't a native control and has no `tabindex >= 0`, so the
171
+ keyboard can't reach it.
172
+ - `ngbr/click-without-key` — a focusable element with a `(click)` handler but no
173
+ keyboard handler, so Enter/Space may not activate it. This is read from
174
+ `window.ng.getListeners` — a **runtime** signal a static template lint can't see
175
+ (e.g. a handler added via `hostDirectives`).
176
+ - `ngbr/tab-order-mismatch` — the tab path jumps against the visual reading order
177
+ (needs real layout, so it fires in report-mode / a real browser).
178
+
179
+ ```bash
180
+ # include the keyboard layer in a report-mode run
181
+ npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
182
+ ```
183
+
184
+ **Honesty guardrail:** `click-without-key` and `tab-order-mismatch` are
185
+ *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".)
188
+
146
189
  ## What it checks (and what it can't)
147
190
 
148
191
  Under the hood this is [axe-core](https://github.com/dequelabs/axe-core) — the
@@ -182,11 +225,14 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
182
225
 
183
226
  ## Roadmap
184
227
 
185
- - Configurable framework-primitive prefixes (PrimeNG, Clarity, Ionic, …).
228
+ - Keyboard & Focus Mode **M2** — accessibility-tree preview (role + accessible
229
+ name + state as you Tab), framed as a *computed approximation*.
230
+ - Keyboard & Focus Mode **M3** — focus-trap *candidate* detection.
186
231
  - HTML report + baseline/diff mode for CI.
187
232
  - Per-component filtering and a violation-count badge.
188
233
 
189
234
  Done: component attribution (nearest app-owned, walking past UI primitives) ·
190
- directive / `hostDirectives` attribution · axe scan · grouped console reporter ·
191
- dev-only provider · in-app overlay · headless report mode (CLI + `./report`) ·
192
- CI prod-weight guard.
235
+ directive / `hostDirectives` attribution · configurable framework prefixes · axe
236
+ scan · grouped console reporter · dev-only provider · in-app overlay · headless
237
+ report mode (CLI + `./report`) · **Keyboard & Focus Mode M1** (tab-order viz +
238
+ keyboard-reachability findings) · CI prod-weight guard.
@@ -16,6 +16,16 @@ Options:
16
16
  --wait <ms> Settle time after load before scanning (default 1500)
17
17
  --fail-on <impact> Exit non-zero if any finding is at/above impact
18
18
  (minor | moderate | serious | critical) — for CI gating
19
+ --framework-prefixes <list>
20
+ Comma-separated component-name prefixes to treat as
21
+ third-party UI primitives to walk past during attribution
22
+ (default: Nb,Mat,Cdk,Mdc). e.g. Nb,Mat,Nz,Clr,Ion
23
+ --no-skip-primitives
24
+ Attribute to the immediate owner (skip nothing) — use when
25
+ scanning a component library's own code
26
+ --keyboard Also run the keyboard layer: heuristic ngbr/* findings for
27
+ keyboard-unreachable controls, click-without-keyboard
28
+ handlers, and visual-vs-tab-order mismatches
19
29
  --headed Launch a visible browser (debugging)
20
30
  -h, --help Show this help
21
31
  `;
@@ -35,6 +45,11 @@ function parseArgs(argv) {
35
45
  case '--format': opts.format = next(); break;
36
46
  case '--wait': opts.wait = Number(next()); break;
37
47
  case '--fail-on': opts.failOn = next(); break;
48
+ case '--framework-prefixes':
49
+ opts.frameworkPrefixes = next().split(',').map((s) => s.trim()).filter(Boolean);
50
+ break;
51
+ case '--no-skip-primitives': opts.frameworkPrefixes = []; break;
52
+ case '--keyboard': opts.keyboard = true; break;
38
53
  case '--headed': opts.headed = true; break;
39
54
  case '-h': case '--help': opts.help = true; break;
40
55
  default: console.error(`Unknown argument: ${arg}\n`); opts.help = true;
@@ -56,6 +71,8 @@ const report = await scanPages({
56
71
  tags: opts.tags,
57
72
  waitMs: opts.wait,
58
73
  headed: opts.headed,
74
+ frameworkPrefixes: opts.frameworkPrefixes,
75
+ keyboard: opts.keyboard,
59
76
  });
60
77
 
61
78
  const allFindings = report.pages.flatMap((p) => p.findings);
@@ -14,8 +14,42 @@ export interface NgDebugGlobal {
14
14
  getComponent(element: Element): unknown;
15
15
  getOwningComponent(element: Element | object): unknown;
16
16
  getDirectives(element: Element | object): unknown[];
17
+ /**
18
+ * Listeners Angular bound to a node — template `(event)` bindings plus
19
+ * `@HostListener`s. Present on the dev global alongside the other helpers; the
20
+ * keyboard scan uses it to see, at runtime, which elements have a `click`
21
+ * handler but no keyboard handler — a case a static template lint can't catch
22
+ * (e.g. a listener added by a directive via `hostDirectives`).
23
+ */
24
+ getListeners?(element: Element): NgListener[];
17
25
  }
26
+ /** Shape of an entry returned by `window.ng.getListeners`. */
27
+ export interface NgListener {
28
+ name: string;
29
+ type?: 'dom' | 'output';
30
+ callback?: unknown;
31
+ useCapture?: boolean;
32
+ }
33
+ /**
34
+ * The DOM event names Angular has a listener bound for on `node` (template
35
+ * `(event)` bindings and `@HostListener`s), lowercased and de-duplicated. Empty
36
+ * when the debug global is absent (prod) or the node has none. Output/`@Output`
37
+ * emitters are excluded — only real DOM events matter for keyboard operability.
38
+ */
39
+ export declare function resolveListenerEvents(node: Element): string[];
18
40
  export declare function ngDebug(): NgDebugGlobal | undefined;
41
+ /**
42
+ * Default component-name prefixes treated as third-party UI primitives (Nebular
43
+ * `Nb*`, Angular Material `Mat*`, CDK `Cdk*`/`Mdc*`) whose violations are fixed
44
+ * where the primitive is *used*, not inside the library — e.g. `<button nbButton>`
45
+ * with no name is fixed in the component that placed it, not in Nebular.
46
+ * Attribution walks past these to the app component. A component library you
47
+ * author (e.g. `Ngbr*`) is deliberately absent: a bug in a component you ship is
48
+ * fixed in that component. Override with the `frameworkPrefixes` option — add
49
+ * `Nz`/`Clr`/`Ion`/`Tui` for other libraries, or pass `[]` to disable walking
50
+ * (attribute to the immediate owner) when scanning a library's own code.
51
+ */
52
+ export declare const DEFAULT_FRAMEWORK_PREFIXES: readonly string[];
19
53
  /**
20
54
  * The chain of owning components from the flagged node up to the root, nearest
21
55
  * first and de-duplicated. Built by walking DOM ancestors and asking Angular's
@@ -23,14 +57,18 @@ export declare function ngDebug(): NgDebugGlobal | undefined;
23
57
  * reveals the app component that placed it. Empty when the global is absent (prod).
24
58
  */
25
59
  export declare function resolveComponentPath(node: Element): string[];
26
- /** The component to blame from an ownership path: the nearest one the app owns. */
27
- export declare function appComponentFromPath(path: string[]): string | null;
60
+ /**
61
+ * The component to blame from an ownership path: the nearest one the app owns,
62
+ * walking past third-party UI primitives. Pass `frameworkPrefixes: []` to skip
63
+ * nothing and return the immediate owner.
64
+ */
65
+ export declare function appComponentFromPath(path: string[], frameworkPrefixes?: readonly string[]): string | null;
28
66
  /**
29
67
  * The owning component name for a flagged node — the nearest component the app
30
68
  * author actually owns (walking past third-party UI primitives to where the fix
31
69
  * lives). Null when the debug global is absent (prod).
32
70
  */
33
- export declare function resolveOwningComponentName(node: Element): string | null;
71
+ export declare function resolveOwningComponentName(node: Element, frameworkPrefixes?: readonly string[]): string | null;
34
72
  /**
35
73
  * Names of the directives applied directly to `node`, including those attached
36
74
  * via `hostDirectives` — the runtime-only a11y cases the static lint plugin
@@ -1,3 +1,29 @@
1
+ /**
2
+ * The DOM event names Angular has a listener bound for on `node` (template
3
+ * `(event)` bindings and `@HostListener`s), lowercased and de-duplicated. Empty
4
+ * when the debug global is absent (prod) or the node has none. Output/`@Output`
5
+ * emitters are excluded — only real DOM events matter for keyboard operability.
6
+ */
7
+ export function resolveListenerEvents(node) {
8
+ const ng = ngDebug();
9
+ if (typeof ng?.getListeners !== 'function')
10
+ return [];
11
+ let listeners;
12
+ try {
13
+ listeners = ng.getListeners(node) ?? [];
14
+ }
15
+ catch {
16
+ return []; // node isn't part of a live view
17
+ }
18
+ const events = new Set();
19
+ for (const listener of listeners) {
20
+ if (listener?.type === 'output')
21
+ continue;
22
+ if (typeof listener?.name === 'string')
23
+ events.add(listener.name.toLowerCase());
24
+ }
25
+ return [...events];
26
+ }
1
27
  export function ngDebug() {
2
28
  return globalThis.ng;
3
29
  }
@@ -16,17 +42,31 @@ function nameOf(instance) {
16
42
  return cleanName(instance.constructor.name ?? null);
17
43
  }
18
44
  /**
19
- * Third-party UI-primitive components (Nebular `Nb*`, Angular Material `Mat*`,
20
- * CDK `Cdk*`/`Mdc*`) whose violations are fixed where the primitive is *used*,
21
- * not inside the library — e.g. `<button nbButton>` with no name is fixed in the
22
- * component that placed it, not in Nebular. Attribution walks past these to the
23
- * app component. Matched with a CamelCase boundary so `MatchListComponent` isn't
24
- * mistaken for Material. A component library you author (e.g. `Ngbr*`) is
25
- * deliberately absent: a bug in a component you ship is fixed in that component.
45
+ * Default component-name prefixes treated as third-party UI primitives (Nebular
46
+ * `Nb*`, Angular Material `Mat*`, CDK `Cdk*`/`Mdc*`) whose violations are fixed
47
+ * where the primitive is *used*, not inside the library — e.g. `<button nbButton>`
48
+ * with no name is fixed in the component that placed it, not in Nebular.
49
+ * Attribution walks past these to the app component. A component library you
50
+ * author (e.g. `Ngbr*`) is deliberately absent: a bug in a component you ship is
51
+ * fixed in that component. Override with the `frameworkPrefixes` option — add
52
+ * `Nz`/`Clr`/`Ion`/`Tui` for other libraries, or pass `[]` to disable walking
53
+ * (attribute to the immediate owner) when scanning a library's own code.
54
+ */
55
+ export const DEFAULT_FRAMEWORK_PREFIXES = ['Nb', 'Mat', 'Cdk', 'Mdc'];
56
+ /**
57
+ * True when `name` starts with one of `prefixes` at a CamelCase boundary, so
58
+ * `MatCard` matches Material but `MatchList` does not. An empty prefix list
59
+ * matches nothing — nothing is treated as a primitive.
26
60
  */
27
- const PRIMITIVE_COMPONENT = /^(Nb|Mat|Cdk|Mdc)[A-Z]/;
28
- function isPrimitiveComponent(name) {
29
- return PRIMITIVE_COMPONENT.test(name);
61
+ function isPrimitiveComponent(name, prefixes) {
62
+ for (const prefix of prefixes) {
63
+ if (!prefix || name.length <= prefix.length || !name.startsWith(prefix))
64
+ continue;
65
+ const next = name.charCodeAt(prefix.length);
66
+ if (next >= 65 && next <= 90)
67
+ return true; // next char is A–Z
68
+ }
69
+ return false;
30
70
  }
31
71
  /**
32
72
  * The chain of owning components from the flagged node up to the root, nearest
@@ -59,17 +99,21 @@ export function resolveComponentPath(node) {
59
99
  }
60
100
  return path;
61
101
  }
62
- /** The component to blame from an ownership path: the nearest one the app owns. */
63
- export function appComponentFromPath(path) {
64
- return path.find((name) => !isPrimitiveComponent(name)) ?? path[0] ?? null;
102
+ /**
103
+ * The component to blame from an ownership path: the nearest one the app owns,
104
+ * walking past third-party UI primitives. Pass `frameworkPrefixes: []` to skip
105
+ * nothing and return the immediate owner.
106
+ */
107
+ export function appComponentFromPath(path, frameworkPrefixes = DEFAULT_FRAMEWORK_PREFIXES) {
108
+ return path.find((name) => !isPrimitiveComponent(name, frameworkPrefixes)) ?? path[0] ?? null;
65
109
  }
66
110
  /**
67
111
  * The owning component name for a flagged node — the nearest component the app
68
112
  * author actually owns (walking past third-party UI primitives to where the fix
69
113
  * lives). Null when the debug global is absent (prod).
70
114
  */
71
- export function resolveOwningComponentName(node) {
72
- return appComponentFromPath(resolveComponentPath(node));
115
+ export function resolveOwningComponentName(node, frameworkPrefixes = DEFAULT_FRAMEWORK_PREFIXES) {
116
+ return appComponentFromPath(resolveComponentPath(node), frameworkPrefixes);
73
117
  }
74
118
  /**
75
119
  * Names of the directives applied directly to `node`, including those attached
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { provideA11yDevtools, type A11yDevtoolsOptions } from './provider.js';
2
2
  export { runA11yScan, type RunOptions } from './runner.js';
3
- export { scan, type A11yFinding, type Impact } from './scan.js';
3
+ export { scan, type A11yFinding, type Impact, type ScanOptions } from './scan.js';
4
4
  export { logFindings, type Logger } from './report.js';
5
- export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, ngDebug, type NgDebugGlobal, } from './attribution.js';
5
+ export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, type NgDebugGlobal, type NgListener, } from './attribution.js';
6
+ export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, } from './keyboard/tab-sequence.js';
7
+ export { scanKeyboard, type KeyboardScanOptions } from './keyboard/keyboard-scan.js';
6
8
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, } from './overlay.js';
package/dist/index.js CHANGED
@@ -2,5 +2,7 @@ export { provideA11yDevtools } from './provider.js';
2
2
  export { runA11yScan } from './runner.js';
3
3
  export { scan } from './scan.js';
4
4
  export { logFindings } from './report.js';
5
- export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, ngDebug, } from './attribution.js';
5
+ export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, } from './attribution.js';
6
+ export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
7
+ export { scanKeyboard } from './keyboard/keyboard-scan.js';
6
8
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
package/dist/inpage.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RunOptions as AxeRunOptions } from 'axe-core';
2
- import { type A11yFinding } from './scan.js';
2
+ import { type A11yFinding, type ScanOptions } from './scan.js';
3
3
  /**
4
4
  * The browser-injected half of report-mode. A headless driver injects the built
5
5
  * IIFE (`dist/inpage.global.js`) into a running **dev** page and calls this
@@ -9,4 +9,4 @@ import { type A11yFinding } from './scan.js';
9
9
  * This entry is deliberately NOT re-exported from `index.ts`: it bundles axe-core
10
10
  * and must never reach a consumer's application bundle.
11
11
  */
12
- export type InPageScan = (options?: AxeRunOptions) => Promise<A11yFinding[]>;
12
+ export type InPageScan = (options?: AxeRunOptions, scanOptions?: ScanOptions) => Promise<A11yFinding[]>;