@ngbracket/a11y-devtools 0.10.0 → 0.10.1
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 +21 -0
- package/README.md +50 -330
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/inpage.global.js +21 -4
- package/dist/keyboard/keyboard-scan.js +6 -1
- package/dist/keyboard/tab-sequence.d.ts +27 -8
- package/dist/keyboard/tab-sequence.js +39 -8
- package/dist/report/baseline.d.ts +4 -1
- package/dist/report/baseline.js +6 -1
- package/dist/report/format.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
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.10.1
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **The JSON report now keeps a failed route's `error`.** Before, a route that
|
|
11
|
+
failed to scan appeared in the JSON as a page with 0 findings, which looks clean.
|
|
12
|
+
Pages now also carry `colorScheme` and `darkOnly` when set.
|
|
13
|
+
- **Baseline: a route that failed in the baseline is skipped** instead of counting
|
|
14
|
+
everything on it as new. Re-record the baseline to cover it.
|
|
15
|
+
- **`ngbr/tab-order-mismatch` no longer flags moving into the next column.** Tab
|
|
16
|
+
going up *and to the right* (from a sidebar into the main content, or across a
|
|
17
|
+
multi-column footer) is normal reading order. Up-and-left, and leftwards on the
|
|
18
|
+
same row, are still flagged. It also now compares where the previous stop *ends*
|
|
19
|
+
with where the next *starts*, using line boxes, so links in wrapped paragraph text
|
|
20
|
+
aren't misread. Found by running the tool on its own docs site. New export type:
|
|
21
|
+
`StopRect`.
|
|
22
|
+
- **`ngbr/unreachable-control` / `ngbr/click-without-key` skip event delegation.** A
|
|
23
|
+
click listener on a container of links or controls (with no interactive role of
|
|
24
|
+
its own) handles clicks on those controls; it isn't a fake button. New export:
|
|
25
|
+
`hasFocusableDescendant`.
|
|
26
|
+
|
|
6
27
|
## 0.10.0
|
|
7
28
|
|
|
8
29
|
### Added
|
package/README.md
CHANGED
|
@@ -1,375 +1,95 @@
|
|
|
1
1
|
# @ngbracket/a11y-devtools
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Accessibility auditing for Angular that maps each axe violation back to **the
|
|
4
|
+
component that rendered it**, so you get `♿ UserCardComponent — 2 issue(s)`, not a
|
|
5
|
+
wall of CSS selectors. Run it as a dev overlay while you build, or headless in CI.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[TanStack's a11y plugin](https://tanstack.com/devtools/latest/docs/plugins/a11y)
|
|
10
|
-
(now cross-framework, with an Angular adapter too) — report the DOM node (selector,
|
|
11
|
-
HTML, rule id) and highlight it, but we haven't seen one tie a violation back to the
|
|
12
|
-
component that rendered it, by name. This does, through Angular's **documented** dev
|
|
13
|
-
debug API (`window.ng`) rather than private framework internals.
|
|
7
|
+
**📖 Documentation: [ngbracket.com/tools/a11y-devtools/docs](https://ngbracket.com/tools/a11y-devtools/docs/introduction)**
|
|
8
|
+
(guides, every option and CLI flag, and the rule catalogue).
|
|
14
9
|
|
|
15
10
|
Part of the `@ngbracket` Angular tooling family.
|
|
16
11
|
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`hostDirectives` — which are the runtime cases a static ESLint pass can't see.
|
|
34
|
-
These helpers exist **only in dev builds** — which is exactly right: the tool is
|
|
35
|
-
dev-only, and the global's absence in prod is the signal to no-op.
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Component attribution**: every finding names the Angular component to fix,
|
|
15
|
+
walking past UI-library components (Material, CDK, Nebular, …) to yours. Uses
|
|
16
|
+
Angular's documented dev debug API (`window.ng`).
|
|
17
|
+
- **In-app provider**: rescans as the app settles; grouped console output and an
|
|
18
|
+
optional on-page overlay.
|
|
19
|
+
- **Report mode**: scan many routes headless from the CLI; Markdown, JSON and a
|
|
20
|
+
self-contained HTML report.
|
|
21
|
+
- **CI gating with a baseline**: fail only on *new* issues, so an app with known
|
|
22
|
+
issues can adopt the gate today.
|
|
23
|
+
- **Dark mode**: scan your dark theme too, whether it follows the OS setting, a
|
|
24
|
+
class, an attribute, or custom logic.
|
|
25
|
+
- **Keyboard & Focus Mode**: tab-order visualisation, keyboard findings,
|
|
26
|
+
accessibility-tree preview, and keyboard-trap detection with real Tab presses.
|
|
27
|
+
- **Zero production weight**: a no-op in production; axe-core is never loaded.
|
|
36
28
|
|
|
37
29
|
## Install
|
|
38
30
|
|
|
39
31
|
```bash
|
|
40
32
|
npm i -D @ngbracket/a11y-devtools
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Peer deps: `@angular/core >=18`, `rxjs >=7`.
|
|
44
|
-
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
// app.config.ts (dev configuration)
|
|
49
|
-
import { provideA11yDevtools } from '@ngbracket/a11y-devtools';
|
|
50
|
-
|
|
51
|
-
export const appConfig = {
|
|
52
|
-
providers: [
|
|
53
|
-
// ...your providers
|
|
54
|
-
provideA11yDevtools(),
|
|
55
|
-
],
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
It rescans whenever the app settles (zoneless-aware, via `ApplicationRef.isStable`)
|
|
60
|
-
and logs violations grouped by owning component. Options:
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
provideA11yDevtools({
|
|
64
|
-
root: () => document.querySelector('main')!, // scan scope; default document
|
|
65
|
-
log: true, // grouped console output; default true
|
|
66
|
-
overlay: true, // in-app visual highlights over flagged nodes; default false
|
|
67
|
-
debounceMs: 500, // quiet window after stabilization before scanning
|
|
68
|
-
tags: ['wcag22aa'], // scope the ruleset; default = axe-core's full ruleset
|
|
69
|
-
frameworkPrefixes: ['Nb', 'Mat', 'Cdk', 'Mdc'], // UI primitives to attribute past (default)
|
|
70
|
-
keyboard: true, // also run the keyboard layer (see below); default false
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Framework prefixes.** Attribution walks *past* third-party UI primitives to the app
|
|
75
|
-
component that placed them — a `<button nbButton>` with no name is blamed on your
|
|
76
|
-
`HeaderComponent`, not `NbButtonComponent`. The default list is `Nb`/`Mat`/`Cdk`/`Mdc`;
|
|
77
|
-
override `frameworkPrefixes` to add others (e.g. `['Nb','Mat','Nz','Clr','Ion']` — spread
|
|
78
|
-
`DEFAULT_FRAMEWORK_PREFIXES` to extend), or pass `[]` to attribute to the **immediate**
|
|
79
|
-
owner (useful when auditing a component library's *own* code). The same option is available
|
|
80
|
-
on `scan`, `runA11yScan`, `scanPages`, and the CLI (`--framework-prefixes` / `--no-skip-primitives`).
|
|
81
|
-
|
|
82
|
-
Findings are grouped by owning component, led by a summary line, and each node's
|
|
83
|
-
directives are shown inline:
|
|
84
|
-
|
|
85
|
-
```text
|
|
86
|
-
♿ a11y-devtools: 2 issue(s) across 1 component(s)
|
|
87
|
-
♿ UserCardComponent — 2 issue(s)
|
|
88
|
-
critical · image-alt: Images must have alternative text [via TooltipDirective]
|
|
89
|
-
img
|
|
90
|
-
https://dequeuniversity.com/rules/axe/4.13/image-alt
|
|
91
|
-
serious · color-contrast: Elements must meet minimum contrast
|
|
92
|
-
button.save
|
|
93
|
-
https://dequeuniversity.com/rules/axe/4.13/color-contrast
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
You can also scan on demand:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
import { runA11yScan, scan } from '@ngbracket/a11y-devtools';
|
|
100
|
-
|
|
101
|
-
const findings = await runA11yScan(); // scan + grouped log
|
|
102
|
-
const raw = await scan(document.body); // findings only
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
`scan()` and `runA11yScan()` also take full axe-core run options as a second
|
|
106
|
-
argument (`scan(root, { runOnly: … })`) for finer control than the provider's
|
|
107
|
-
`tags`.
|
|
108
|
-
|
|
109
|
-
## Report mode (headless, CI-friendly)
|
|
110
|
-
|
|
111
|
-
The provider is for while you're developing a page. **Report mode** turns the same
|
|
112
|
-
engine on a whole running app from the outside: it drives a headless browser over
|
|
113
|
-
your **dev** server, injects the same component-attributed scan, and writes a
|
|
114
|
-
report grouped by owning component — with no change to the app under test. It needs
|
|
115
|
-
a dev build, because that's what publishes `window.ng` for attribution; against a
|
|
116
|
-
production build, attribution falls back to `(unknown component)`.
|
|
117
|
-
|
|
118
|
-
Report mode is opt-in and needs Playwright, an **optional peer** you install
|
|
119
|
-
yourself (so the base package stays weightless):
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
npm i -D playwright
|
|
123
|
-
npx playwright install chromium
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Start your app (`ng serve`), then point the CLI at it:
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
# writes a11y.md and a11y.json
|
|
130
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard --out a11y
|
|
131
|
-
|
|
132
|
-
# …or pick formats: md, json, html (comma-separated), both (= md,json) or all
|
|
133
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --out a11y --format all
|
|
134
|
-
|
|
135
|
-
# CI gate: exit non-zero on any serious/critical finding
|
|
136
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --fail-on serious
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### HTML report
|
|
140
|
-
|
|
141
|
-
`--format html` (or `all`) writes one self-contained `.html` file. It has no
|
|
142
|
-
scripts and makes no external requests, so you can attach it to a CI run, email it,
|
|
143
|
-
or open it offline. It has the same content as the Markdown report, and it's
|
|
144
|
-
accessible itself: landmarks, a sequential heading outline, a real data table,
|
|
145
|
-
severity written as text (not colour alone), and AA contrast in light and dark
|
|
146
|
-
mode. Its own report-mode scan comes back clean.
|
|
147
33
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
By default the headless browser reports a **light** colour-scheme preference, so a
|
|
151
|
-
dark theme is never switched on and its contrast is never checked. Pick the
|
|
152
|
-
scheme(s) to scan with `--color-scheme`:
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
# dark theme driven by prefers-color-scheme (the OS setting)
|
|
156
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --color-scheme both
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
- `light` (default) or `dark` scans once in that scheme. Dark pages are labelled
|
|
160
|
-
`/route (dark)`.
|
|
161
|
-
- `both` scans each route twice. To avoid listing everything twice, the dark page
|
|
162
|
-
shows only the issues that **don't also** appear in light mode (typically contrast
|
|
163
|
-
problems specific to the dark palette).
|
|
164
|
-
|
|
165
|
-
Many apps switch themes with a class or attribute instead of the OS setting. For
|
|
166
|
-
those, tell report mode what to set on `<html>` for the dark pass (either flag
|
|
167
|
-
implies `--color-scheme both`):
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --dark-class dark # Tailwind-style
|
|
171
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --dark-attribute data-bs-theme=dark # Bootstrap
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
For anything else (a theme picker, a setting in localStorage, a class on `<body>`),
|
|
175
|
-
use the programmatic hooks. Both receive the pass's `colorScheme`:
|
|
176
|
-
|
|
177
|
-
```ts
|
|
178
|
-
await scanPages({
|
|
179
|
-
baseUrl: 'http://localhost:4200',
|
|
180
|
-
routes: ['/', '/settings'],
|
|
181
|
-
colorScheme: 'both',
|
|
182
|
-
// once per pass, e.g. pick the theme in a persisted setting
|
|
183
|
-
setup: async (page, { colorScheme }) => {
|
|
184
|
-
await page.evaluate((s) => localStorage.setItem('theme', s), colorScheme);
|
|
185
|
-
},
|
|
186
|
-
// after every route loads, for a theme that doesn't persist between pages
|
|
187
|
-
beforeScan: async (page, { colorScheme }) => {
|
|
188
|
-
if (colorScheme === 'dark') await page.click('button[aria-label="Dark theme"]');
|
|
189
|
-
},
|
|
190
|
-
});
|
|
34
|
+
# for report mode only
|
|
35
|
+
npm i -D playwright && npx playwright install chromium
|
|
191
36
|
```
|
|
192
37
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
An app with a backlog of known issues can't turn on `--fail-on` without every build
|
|
196
|
-
failing. A **baseline** fixes that. Save one run's JSON report, commit it, and
|
|
197
|
-
compare later runs against it:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
# once: record today's state (commit a11y-baseline.json)
|
|
201
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard \
|
|
202
|
-
--out a11y-baseline --format json
|
|
203
|
-
|
|
204
|
-
# in CI: fail only on findings that aren't in the baseline
|
|
205
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /dashboard \
|
|
206
|
-
--baseline a11y-baseline.json --fail-on serious --out a11y --format all
|
|
207
|
-
```
|
|
38
|
+
Needs Angular 18+.
|
|
208
39
|
|
|
209
|
-
|
|
210
|
-
the build, and the report shows what's **new**, **fixed** and **unchanged**.
|
|
211
|
-
- A finding's identity is its route, rule, owning component and element selector.
|
|
212
|
-
Angular's per-build `_ngcontent-…` style hashes are ignored, and so is reworded help
|
|
213
|
-
text after an axe upgrade.
|
|
214
|
-
- A route the baseline never scanned counts as entirely new, so re-record the
|
|
215
|
-
baseline when you add routes. A route that fails to scan isn't reported as "fixed".
|
|
216
|
-
- To ratchet down, re-record the baseline after fixing issues. The JSON from any run
|
|
217
|
-
(including a `--baseline` run) is itself a valid baseline.
|
|
40
|
+
## Quick start
|
|
218
41
|
|
|
219
|
-
|
|
220
|
-
`setup` hook (run once before the routes are scanned):
|
|
42
|
+
While you build:
|
|
221
43
|
|
|
222
44
|
```ts
|
|
223
|
-
|
|
45
|
+
// app.config.ts
|
|
46
|
+
import { provideA11yDevtools } from '@ngbracket/a11y-devtools';
|
|
224
47
|
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
setup: async (page) => {
|
|
229
|
-
await page.goto('http://localhost:4200/login');
|
|
230
|
-
await page.fill('#email', 'demo@example.com');
|
|
231
|
-
await page.click('button[type=submit]');
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
console.log(toMarkdown(report));
|
|
48
|
+
export const appConfig: ApplicationConfig = {
|
|
49
|
+
providers: [provideA11yDevtools({ overlay: true, keyboard: true })],
|
|
50
|
+
};
|
|
235
51
|
```
|
|
236
52
|
|
|
237
|
-
The same pieces are exported for your own pipeline: `toJson`, `toHtml`,
|
|
238
|
-
`parseBaseline` and `diffAgainstBaseline` (pass the diff as the second argument to
|
|
239
|
-
`toMarkdown` / `toJson` / `toHtml`).
|
|
240
|
-
|
|
241
|
-
The report leads with a summary of **distinct rules vs. raw node-instances** (a
|
|
242
|
-
"54" is usually one rule firing dozens of times), then lists findings under each
|
|
243
|
-
owning component. When a flagged control is itself a third-party UI primitive
|
|
244
|
-
(e.g. `<button nbButton>`), attribution walks past the primitive to the app
|
|
245
|
-
component that placed it and notes the primitive as `(via …)`.
|
|
246
|
-
|
|
247
|
-
## Keyboard & Focus Mode (the ~2/3 axe can't test)
|
|
248
|
-
|
|
249
|
-
axe covers the machine-testable third of WCAG. **Keyboard & Focus Mode** starts on
|
|
250
|
-
the rest — keyboard operability — still naming the component that owns each issue.
|
|
251
|
-
Turn it on with `keyboard: true` (provider / `runA11yScan` / `scan` / `scanPages`)
|
|
252
|
-
or `--keyboard` on the CLI.
|
|
253
|
-
|
|
254
53
|

|
|
259
58
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
- **Tab-order visualisation** (overlay): numbered badges at each tab stop and a
|
|
263
|
-
connector path showing the order focus actually moves. A positive-`tabindex` stop
|
|
264
|
-
is coloured as a warning, because it hijacks the natural order.
|
|
265
|
-
- **Keyboard findings**, grouped and reported exactly like the axe violations:
|
|
266
|
-
- `ngbr/unreachable-control` — an interactive element (an ARIA role, or a runtime
|
|
267
|
-
`click` listener) that isn't a native control and has no `tabindex >= 0`, so the
|
|
268
|
-
keyboard can't reach it.
|
|
269
|
-
- `ngbr/click-without-key` — a focusable element with a `(click)` handler but no
|
|
270
|
-
keyboard handler, so Enter/Space may not activate it. This is read from
|
|
271
|
-
`window.ng.getListeners` — a **runtime** signal a static template lint can't see
|
|
272
|
-
(e.g. a handler added via `hostDirectives`).
|
|
273
|
-
- `ngbr/tab-order-mismatch` — the tab path jumps against the visual reading order
|
|
274
|
-
(needs real layout, so it fires in report-mode / a real browser).
|
|
275
|
-
- `ngbr/modal-focus-not-contained` — an open `aria-modal="true"` whose focus isn't
|
|
276
|
-
contained: tabbable elements outside it are still reachable, so a keyboard user
|
|
277
|
-
can Tab out to the page behind. (A modal that correctly marks the background
|
|
278
|
-
`inert` is not flagged, since those elements are no longer tabbable.)
|
|
279
|
-
|
|
280
|
-
```bash
|
|
281
|
-
# include the keyboard layer in a report-mode run
|
|
282
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --keyboard
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
**Honesty guardrail:** `click-without-key`, `tab-order-mismatch`,
|
|
286
|
-
`modal-focus-not-contained` and `focus-trap` are *heuristics*. They're labelled
|
|
287
|
-
"verify manually" and never reported as confirmed failures.
|
|
288
|
-
|
|
289
|
-
### Keyboard traps (report-mode, M3)
|
|
290
|
-
|
|
291
|
-
A keyboard trap is focus you can Tab *into* but never Tab *out of*
|
|
292
|
-
([WCAG 2.1.2](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html)).
|
|
293
|
-
You can't find one by reading the DOM. Script makes the trap, by intercepting Tab or
|
|
294
|
-
re-focusing on blur, and synthetic key events don't move focus in a browser. So
|
|
295
|
-
report-mode presses the **real** Tab key through each route:
|
|
59
|
+
In CI, against a running `ng serve`:
|
|
296
60
|
|
|
297
61
|
```bash
|
|
298
|
-
npx ngbr-a11y-report --base http://localhost:4200 --route / --
|
|
62
|
+
npx ngbr-a11y-report --base http://localhost:4200 --route / --route /settings \
|
|
63
|
+
--keyboard --baseline a11y-baseline.json --fail-on serious --out a11y --format all
|
|
299
64
|
```
|
|
300
65
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
- Focus cycling inside an open `aria-modal` / `<dialog>` is containment working,
|
|
308
|
-
so it isn't reported. Consecutive focus on an `<iframe>` (Tab moving inside the
|
|
309
|
-
frame) isn't read as a trap either.
|
|
66
|
+
Next steps, in the docs:
|
|
67
|
+
[Your first scan](https://ngbracket.com/tools/a11y-devtools/docs/first-scan) ·
|
|
68
|
+
[Report mode](https://ngbracket.com/tools/a11y-devtools/docs/report-mode) ·
|
|
69
|
+
[CI gating with a baseline](https://ngbracket.com/tools/a11y-devtools/docs/ci-baseline) ·
|
|
70
|
+
[CLI reference](https://ngbracket.com/tools/a11y-devtools/docs/cli) ·
|
|
71
|
+
[Findings & rules](https://ngbracket.com/tools/a11y-devtools/docs/findings)
|
|
310
72
|
|
|
311
|
-
|
|
312
|
-
that *changes the page*. Pressing Tab can fire focus handlers and open menus, so
|
|
313
|
-
it runs after the scan. A widget that deliberately keeps Tab, like a code editor,
|
|
314
|
-
is fine if it tells users how to leave (Escape, for example). That's why the finding
|
|
315
|
-
says "verify manually".
|
|
73
|
+
## What it can't do
|
|
316
74
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
axe-core's own accessible-name commons (one accname source, shared with the scan),
|
|
323
|
-
and a missing accessible name is flagged in warning colour.
|
|
324
|
-
|
|
325
|
-
> **Accessibility-tree preview — computed approximation.** This is a *computed*
|
|
326
|
-
> name/role/state, an approximation of what assistive tech announces — **not** what
|
|
327
|
-
> any one screen reader says. Real output varies by screen reader (NVDA / JAWS /
|
|
328
|
-
> VoiceOver), browse vs. focus mode, verbosity, and browser. Use it to catch
|
|
329
|
-
> missing names and wrong roles fast; confirm the announcement with a real SR.
|
|
330
|
-
|
|
331
|
-
The same computation is available programmatically via `describeElement(el)`
|
|
332
|
-
(async — it loads axe on demand), plus the pure `ariaStates(el)` and
|
|
333
|
-
`accessibleDescription(el)` helpers.
|
|
334
|
-
|
|
335
|
-
## What it checks (and what it can't)
|
|
336
|
-
|
|
337
|
-
Under the hood this is [axe-core](https://github.com/dequelabs/axe-core) — the
|
|
338
|
-
scan runs axe's rules and enriches each violation with the owning component. By
|
|
339
|
-
default it runs axe-core's full ruleset: the **machine-testable** rules across
|
|
340
|
-
**WCAG 2.0, 2.1 and 2.2, Levels A & AA**, plus axe's *best-practice* rules. Scope
|
|
341
|
-
it to a single conformance target with `tags` (e.g. `['wcag22aa']`) or
|
|
342
|
-
`['wcag21aa', 'best-practice']`.
|
|
343
|
-
|
|
344
|
-
Automated checks only cover the part of WCAG a machine can test — on the order of
|
|
345
|
-
a third of the success criteria. Many WCAG 2.2 additions have **no automated rule
|
|
346
|
-
at all** (target size 2.5.8, dragging 2.5.7, consistent help, redundant entry,
|
|
347
|
-
accessible authentication), so a clean run is necessary, not sufficient — the rest
|
|
348
|
-
needs keyboard, screen-reader and human testing. (WCAG 3.0 is still an early W3C
|
|
349
|
-
draft with a different, non-final model; there's nothing to test against yet.)
|
|
350
|
-
|
|
351
|
-
## Production weight
|
|
352
|
-
|
|
353
|
-
In production `provideA11yDevtools()` is a **no-op** and axe-core is never loaded.
|
|
354
|
-
axe-core is a **dynamic import**, so it lands in a lazy chunk that prod never
|
|
355
|
-
fetches, and the package is `sideEffects: false` so an unused import tree-shakes
|
|
356
|
-
away entirely. For a hard guarantee, include the provider only in your dev
|
|
357
|
-
bootstrap config (e.g. behind `isDevMode()`).
|
|
358
|
-
|
|
359
|
-
This is **enforced in CI**: `src/testing/prod-weight.spec.ts` bundles the entry
|
|
360
|
-
with esbuild and walks the module graph — axe-core must be reachable *only*
|
|
361
|
-
through a dynamic import, never a static one. Turning `import('axe-core')` into a
|
|
362
|
-
static import (or adding a top-level side effect) fails the build.
|
|
75
|
+
Automated checks cover part of WCAG, so a clean run is necessary, not sufficient:
|
|
76
|
+
keyboard, screen-reader and human testing cover the rest. The keyboard findings are
|
|
77
|
+
heuristics, labelled "verify manually". It helps you build toward supporting WCAG
|
|
78
|
+
2.2 AA; it doesn't certify conformance. See
|
|
79
|
+
[What it checks (and what it can't)](https://ngbracket.com/tools/a11y-devtools/docs/coverage).
|
|
363
80
|
|
|
364
81
|
## Develop
|
|
365
82
|
|
|
366
83
|
```bash
|
|
367
84
|
npm install --legacy-peer-deps
|
|
85
|
+
npm run build # tsc -> dist/ (ESM + .d.ts) + the in-page bundle
|
|
368
86
|
npm test # vitest + jsdom + Angular TestBed (real axe); the real-browser
|
|
369
87
|
# E2E spec runs after a build, once `npx playwright install chromium`
|
|
370
|
-
npm run build # tsc -> dist/ (ESM + .d.ts)
|
|
371
88
|
```
|
|
372
89
|
|
|
90
|
+
CI also runs a production-weight guard: a bundle-graph test that fails if axe-core
|
|
91
|
+
ever becomes reachable through a static import.
|
|
92
|
+
|
|
373
93
|
## Roadmap
|
|
374
94
|
|
|
375
95
|
### Planned
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { runA11yScan, type RunOptions } from './runner.js';
|
|
|
3
3
|
export { scan, type A11yFinding, type Impact, type ScanOptions } from './scan.js';
|
|
4
4
|
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
|
-
export { tabSequence, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, } from './keyboard/tab-sequence.js';
|
|
6
|
+
export { tabSequence, hasFocusableDescendant, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, type TabStop, type TabSequenceOptions, type StopRect, } from './keyboard/tab-sequence.js';
|
|
7
7
|
export { scanKeyboard, type KeyboardScanOptions } from './keyboard/keyboard-scan.js';
|
|
8
8
|
export { findUncontainedModals, type UncontainedModal } from './keyboard/focus-trap.js';
|
|
9
9
|
export { createFocusWalkProbe, detectTabTrap, type FocusObservation, type FocusWalkProbe, type TabWalkVerdict, } from './keyboard/focus-walk.js';
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { runA11yScan } from './runner.js';
|
|
|
3
3
|
export { scan } from './scan.js';
|
|
4
4
|
export { logFindings } from './report.js';
|
|
5
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';
|
|
6
|
+
export { tabSequence, hasFocusableDescendant, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
|
|
7
7
|
export { scanKeyboard } from './keyboard/keyboard-scan.js';
|
|
8
8
|
export { findUncontainedModals } from './keyboard/focus-trap.js';
|
|
9
9
|
export { createFocusWalkProbe, detectTabTrap, } from './keyboard/focus-walk.js';
|
package/dist/inpage.global.js
CHANGED
|
@@ -34239,6 +34239,9 @@
|
|
|
34239
34239
|
"[contenteditable]",
|
|
34240
34240
|
"[tabindex]"
|
|
34241
34241
|
].join(",");
|
|
34242
|
+
function hasFocusableDescendant(element) {
|
|
34243
|
+
return element.querySelector(FOCUSABLE_SELECTOR) !== null;
|
|
34244
|
+
}
|
|
34242
34245
|
function nativeTabIndex(element) {
|
|
34243
34246
|
return isNativelyFocusable(element) ? 0 : -1;
|
|
34244
34247
|
}
|
|
@@ -34335,14 +34338,26 @@
|
|
|
34335
34338
|
};
|
|
34336
34339
|
});
|
|
34337
34340
|
}
|
|
34338
|
-
function
|
|
34341
|
+
function stopRect(el) {
|
|
34342
|
+
const box = el.getBoundingClientRect();
|
|
34343
|
+
const lines = el.getClientRects();
|
|
34344
|
+
if (lines.length === 0)
|
|
34345
|
+
return { top: box.top, left: box.left, right: box.right };
|
|
34346
|
+
const first = lines[0];
|
|
34347
|
+
const last = lines[lines.length - 1];
|
|
34348
|
+
return { top: first.top, left: first.left, right: box.right, endTop: last.top, endLeft: last.left };
|
|
34349
|
+
}
|
|
34350
|
+
function visualOrderJumps(stops, getRect = stopRect, rowThreshold = 8) {
|
|
34339
34351
|
const jumps = [];
|
|
34340
34352
|
for (let i = 1; i < stops.length; i++) {
|
|
34341
34353
|
const prev = getRect(stops[i - 1].element);
|
|
34342
34354
|
const curr = getRect(stops[i].element);
|
|
34343
|
-
const
|
|
34344
|
-
const
|
|
34345
|
-
|
|
34355
|
+
const prevTop = prev.endTop ?? prev.top;
|
|
34356
|
+
const prevLeft = prev.endLeft ?? prev.left;
|
|
34357
|
+
const movedUp = curr.top < prevTop - rowThreshold;
|
|
34358
|
+
const nextColumn = curr.left >= (prev.right ?? prev.left + rowThreshold);
|
|
34359
|
+
const sameRowMovedLeft = Math.abs(curr.top - prevTop) <= rowThreshold && curr.left < prevLeft - rowThreshold;
|
|
34360
|
+
if (movedUp && !nextColumn || sameRowMovedLeft)
|
|
34346
34361
|
jumps.push(i);
|
|
34347
34362
|
}
|
|
34348
34363
|
return jumps;
|
|
@@ -34431,6 +34446,8 @@
|
|
|
34431
34446
|
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
34432
34447
|
if (!hasClick && !interactiveByRole)
|
|
34433
34448
|
continue;
|
|
34449
|
+
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
34450
|
+
continue;
|
|
34434
34451
|
const focusable = isTabbable(element, isVisible);
|
|
34435
34452
|
if (!focusable) {
|
|
34436
34453
|
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* confirmed failures.
|
|
13
13
|
*/
|
|
14
14
|
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
|
|
15
|
-
import { isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
15
|
+
import { hasFocusableDescendant, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
16
16
|
import { findUncontainedModals } from './focus-trap.js';
|
|
17
17
|
/** WAI-ARIA roles that make a non-native element behave as an interactive control. */
|
|
18
18
|
const INTERACTIVE_ROLES = new Set([
|
|
@@ -90,6 +90,11 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
90
90
|
const interactiveByRole = INTERACTIVE_ROLES.has(role);
|
|
91
91
|
if (!hasClick && !interactiveByRole)
|
|
92
92
|
continue; // nothing marks this as interactive
|
|
93
|
+
// A click listener on a container of links/controls (no interactive role of
|
|
94
|
+
// its own) is event delegation, not a control — the controls inside are what
|
|
95
|
+
// the keyboard reaches.
|
|
96
|
+
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
97
|
+
continue;
|
|
93
98
|
const focusable = isTabbable(element, isVisible);
|
|
94
99
|
if (!focusable) {
|
|
95
100
|
const reason = interactiveByRole ? `has role="${role}"` : 'has a click handler';
|
|
@@ -21,6 +21,12 @@ export interface TabSequenceOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
isVisible?: (element: Element) => boolean;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* True when `element` contains something focusable (a link, control, or
|
|
26
|
+
* `tabindex` element). A click listener on such a container is almost always
|
|
27
|
+
* event delegation — handling clicks on the controls inside — not a fake button.
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasFocusableDescendant(element: Element): boolean;
|
|
24
30
|
/**
|
|
25
31
|
* True when the element takes focus without an explicit `tabindex` — a link with
|
|
26
32
|
* an href, a form control, a `<summary>`, an editing host, and the embedded
|
|
@@ -45,14 +51,27 @@ export declare function isTabbable(element: Element, isVisible?: (el: Element) =
|
|
|
45
51
|
* browser actually moves focus. Each stop carries its owning component.
|
|
46
52
|
*/
|
|
47
53
|
export declare function tabSequence(root?: ParentNode, options?: TabSequenceOptions): TabStop[];
|
|
54
|
+
/** Where a stop starts and ends on screen, for {@link visualOrderJumps}. */
|
|
55
|
+
export interface StopRect {
|
|
56
|
+
/** Top-left of where the element starts (its first line box, for wrapped inline text). */
|
|
57
|
+
top: number;
|
|
58
|
+
left: number;
|
|
59
|
+
/** Right edge of the whole element. */
|
|
60
|
+
right?: number;
|
|
61
|
+
/** Top-left of where it ends (its last line box); defaults to `top`/`left`. */
|
|
62
|
+
endTop?: number;
|
|
63
|
+
endLeft?: number;
|
|
64
|
+
}
|
|
48
65
|
/**
|
|
49
66
|
* Indices (0-based, into the sequence) where the tab path jumps *backward against
|
|
50
|
-
* reading order* — a stop that sits clearly above
|
|
51
|
-
*
|
|
52
|
-
* has drifted from the visual order a sighted keyboard user
|
|
53
|
-
* "verify manually". `getRect` is injectable for tests.
|
|
67
|
+
* reading order* — a stop that sits clearly above the stop before it (without
|
|
68
|
+
* moving right), or well to the left on the same row. A heuristic signal that
|
|
69
|
+
* DOM/tabindex order has drifted from the visual order a sighted keyboard user
|
|
70
|
+
* expects; always "verify manually". `getRect` is injectable for tests.
|
|
71
|
+
*
|
|
72
|
+
* Moving up into the *next column* — starting right of where the previous stop
|
|
73
|
+
* ends, like a sidebar then the main content, or across a multi-column footer —
|
|
74
|
+
* is normal reading order, so it isn't a jump. (A stop that moves up but still
|
|
75
|
+
* overlaps the previous one horizontally is.)
|
|
54
76
|
*/
|
|
55
|
-
export declare function visualOrderJumps(stops: readonly TabStop[], getRect?: (el: Element) =>
|
|
56
|
-
top: number;
|
|
57
|
-
left: number;
|
|
58
|
-
}, rowThreshold?: number): number[];
|
|
77
|
+
export declare function visualOrderJumps(stops: readonly TabStop[], getRect?: (el: Element) => StopRect, rowThreshold?: number): number[];
|
|
@@ -28,6 +28,14 @@ const FOCUSABLE_SELECTOR = [
|
|
|
28
28
|
'[contenteditable]',
|
|
29
29
|
'[tabindex]',
|
|
30
30
|
].join(',');
|
|
31
|
+
/**
|
|
32
|
+
* True when `element` contains something focusable (a link, control, or
|
|
33
|
+
* `tabindex` element). A click listener on such a container is almost always
|
|
34
|
+
* event delegation — handling clicks on the controls inside — not a fake button.
|
|
35
|
+
*/
|
|
36
|
+
export function hasFocusableDescendant(element) {
|
|
37
|
+
return element.querySelector(FOCUSABLE_SELECTOR) !== null;
|
|
38
|
+
}
|
|
31
39
|
/** A native default of 0 (focusable without a tabindex attribute), else -1. */
|
|
32
40
|
function nativeTabIndex(element) {
|
|
33
41
|
return isNativelyFocusable(element) ? 0 : -1;
|
|
@@ -157,21 +165,44 @@ export function tabSequence(root = document, options = {}) {
|
|
|
157
165
|
};
|
|
158
166
|
});
|
|
159
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* The default {@link StopRect}: an inline link that wraps across lines starts on
|
|
170
|
+
* one line and ends on the next, and its bounding box starts at the left edge —
|
|
171
|
+
* so compare line boxes, not the bounding box.
|
|
172
|
+
*/
|
|
173
|
+
function stopRect(el) {
|
|
174
|
+
const box = el.getBoundingClientRect();
|
|
175
|
+
const lines = el.getClientRects();
|
|
176
|
+
if (lines.length === 0)
|
|
177
|
+
return { top: box.top, left: box.left, right: box.right };
|
|
178
|
+
const first = lines[0];
|
|
179
|
+
const last = lines[lines.length - 1];
|
|
180
|
+
return { top: first.top, left: first.left, right: box.right, endTop: last.top, endLeft: last.left };
|
|
181
|
+
}
|
|
160
182
|
/**
|
|
161
183
|
* Indices (0-based, into the sequence) where the tab path jumps *backward against
|
|
162
|
-
* reading order* — a stop that sits clearly above
|
|
163
|
-
*
|
|
164
|
-
* has drifted from the visual order a sighted keyboard user
|
|
165
|
-
* "verify manually". `getRect` is injectable for tests.
|
|
184
|
+
* reading order* — a stop that sits clearly above the stop before it (without
|
|
185
|
+
* moving right), or well to the left on the same row. A heuristic signal that
|
|
186
|
+
* DOM/tabindex order has drifted from the visual order a sighted keyboard user
|
|
187
|
+
* expects; always "verify manually". `getRect` is injectable for tests.
|
|
188
|
+
*
|
|
189
|
+
* Moving up into the *next column* — starting right of where the previous stop
|
|
190
|
+
* ends, like a sidebar then the main content, or across a multi-column footer —
|
|
191
|
+
* is normal reading order, so it isn't a jump. (A stop that moves up but still
|
|
192
|
+
* overlaps the previous one horizontally is.)
|
|
166
193
|
*/
|
|
167
|
-
export function visualOrderJumps(stops, getRect =
|
|
194
|
+
export function visualOrderJumps(stops, getRect = stopRect, rowThreshold = 8) {
|
|
168
195
|
const jumps = [];
|
|
169
196
|
for (let i = 1; i < stops.length; i++) {
|
|
170
197
|
const prev = getRect(stops[i - 1].element);
|
|
171
198
|
const curr = getRect(stops[i].element);
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
199
|
+
// Compare where the previous stop *ends* with where this one *starts*.
|
|
200
|
+
const prevTop = prev.endTop ?? prev.top;
|
|
201
|
+
const prevLeft = prev.endLeft ?? prev.left;
|
|
202
|
+
const movedUp = curr.top < prevTop - rowThreshold;
|
|
203
|
+
const nextColumn = curr.left >= (prev.right ?? prev.left + rowThreshold);
|
|
204
|
+
const sameRowMovedLeft = Math.abs(curr.top - prevTop) <= rowThreshold && curr.left < prevLeft - rowThreshold;
|
|
205
|
+
if ((movedUp && !nextColumn) || sameRowMovedLeft)
|
|
175
206
|
jumps.push(i);
|
|
176
207
|
}
|
|
177
208
|
return jumps;
|
|
@@ -15,6 +15,7 @@ export interface BaselineReport {
|
|
|
15
15
|
pages: {
|
|
16
16
|
label: string;
|
|
17
17
|
findings: A11yFinding[];
|
|
18
|
+
error?: string;
|
|
18
19
|
}[];
|
|
19
20
|
}
|
|
20
21
|
/** One finding that's in the current run but not the baseline. */
|
|
@@ -50,7 +51,9 @@ export declare function findingsNotIn(findings: A11yFinding[], reference: A11yFi
|
|
|
50
51
|
* leaves one new. Pages are matched by label; a route the baseline never
|
|
51
52
|
* scanned counts entirely as new (add it to the baseline when you add it to CI).
|
|
52
53
|
* Pages that failed to scan in the current run are skipped, so an outage
|
|
53
|
-
* doesn't report everything on that page as fixed.
|
|
54
|
+
* doesn't report everything on that page as fixed. Pages that failed in the
|
|
55
|
+
* *baseline* are skipped too — there's nothing to compare against, so their
|
|
56
|
+
* current findings aren't counted as new (re-record the baseline to cover them).
|
|
54
57
|
*/
|
|
55
58
|
export declare function diffAgainstBaseline(current: ScanReport, baseline: BaselineReport): BaselineDiff;
|
|
56
59
|
/**
|
package/dist/report/baseline.js
CHANGED
|
@@ -40,10 +40,13 @@ export function findingsNotIn(findings, reference) {
|
|
|
40
40
|
* leaves one new. Pages are matched by label; a route the baseline never
|
|
41
41
|
* scanned counts entirely as new (add it to the baseline when you add it to CI).
|
|
42
42
|
* Pages that failed to scan in the current run are skipped, so an outage
|
|
43
|
-
* doesn't report everything on that page as fixed.
|
|
43
|
+
* doesn't report everything on that page as fixed. Pages that failed in the
|
|
44
|
+
* *baseline* are skipped too — there's nothing to compare against, so their
|
|
45
|
+
* current findings aren't counted as new (re-record the baseline to cover them).
|
|
44
46
|
*/
|
|
45
47
|
export function diffAgainstBaseline(current, baseline) {
|
|
46
48
|
const failed = new Set(current.pages.filter((p) => p.error).map((p) => p.label));
|
|
49
|
+
const baselineFailed = new Set(baseline.pages.filter((p) => p.error).map((p) => p.label));
|
|
47
50
|
const remaining = new Map();
|
|
48
51
|
for (const page of baseline.pages) {
|
|
49
52
|
if (failed.has(page.label))
|
|
@@ -60,6 +63,8 @@ export function diffAgainstBaseline(current, baseline) {
|
|
|
60
63
|
const added = [];
|
|
61
64
|
let unchanged = 0;
|
|
62
65
|
for (const page of current.pages) {
|
|
66
|
+
if (baselineFailed.has(page.label))
|
|
67
|
+
continue;
|
|
63
68
|
for (const finding of page.findings) {
|
|
64
69
|
const bucket = remaining.get(findingKey(page.label, finding));
|
|
65
70
|
if (bucket && bucket.length > 0) {
|
package/dist/report/format.js
CHANGED
|
@@ -59,6 +59,10 @@ export function toJson(report, diff) {
|
|
|
59
59
|
pages: report.pages.map((p) => ({
|
|
60
60
|
label: p.label,
|
|
61
61
|
url: p.url,
|
|
62
|
+
// A failed route must not read as a clean one: keep its error.
|
|
63
|
+
...(p.error !== undefined && { error: p.error }),
|
|
64
|
+
...(p.colorScheme && { colorScheme: p.colorScheme }),
|
|
65
|
+
...(p.darkOnly && { darkOnly: true }),
|
|
62
66
|
distinctRules: distinctRuleCount(p.findings),
|
|
63
67
|
nodeInstances: p.findings.length,
|
|
64
68
|
findings: p.findings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
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",
|