@ngbracket/a11y-devtools 0.18.0 → 0.18.2
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 +26 -0
- package/bin/ngbr-a11y-report.mjs +2 -1
- package/dist/inpage.global.js +14 -1
- package/dist/keyboard/keyboard-scan.js +30 -2
- package/dist/report/serve.d.ts +4 -3
- package/dist/report/serve.js +59 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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.18.2
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- `--serve` stops as soon as the Angular build fails. `ng serve` keeps
|
|
11
|
+
watching after a failed build and never answers, so report mode used to wait
|
|
12
|
+
the full `--serve-timeout` (180 s by default) and then say the server didn't
|
|
13
|
+
answer. It now waits until Angular has printed the build errors, stops the
|
|
14
|
+
server, and exits with code 2 and "The Angular build failed", followed by
|
|
15
|
+
the last lines of output. Both the application builder and the older
|
|
16
|
+
webpack builder are covered. `--serve-timeout` still applies to servers
|
|
17
|
+
that never print a failure.
|
|
18
|
+
|
|
19
|
+
## 0.18.1
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- `ngbr/unreachable-control` no longer reports the touch target in Angular
|
|
24
|
+
Material 15 to 21 checkboxes and radio buttons
|
|
25
|
+
(`.mat-mdc-checkbox-touch-target`, `.mat-mdc-radio-touch-target`). The
|
|
26
|
+
target is an empty element with a click handler that toggles the native
|
|
27
|
+
input beside it, and Tab reaches that input. The rule now skips an empty
|
|
28
|
+
element with a click listener and no role when its parent holds a checkbox
|
|
29
|
+
or radio input. The same element beside a text field or a button is still
|
|
30
|
+
reported. Material 22 removed the handler, so apps on 22 were not affected.
|
|
31
|
+
|
|
6
32
|
## 0.18.0
|
|
7
33
|
|
|
8
34
|
### Added
|
package/bin/ngbr-a11y-report.mjs
CHANGED
|
@@ -28,7 +28,8 @@ Options:
|
|
|
28
28
|
answers, scan, then stop it — e.g. --serve "npx ng serve".
|
|
29
29
|
If --base already answers, that server is used as-is
|
|
30
30
|
--serve-timeout <s>
|
|
31
|
-
Seconds to wait for --serve to answer (default 180)
|
|
31
|
+
Seconds to wait for --serve to answer (default 180).
|
|
32
|
+
A failed Angular build stops it straight away
|
|
32
33
|
--route <path> Route to scan; repeat for multiple routes
|
|
33
34
|
--from <file> Don't scan: read a previous run's JSON report (from --out)
|
|
34
35
|
and write it in the --format(s) asked for — e.g. add an
|
package/dist/inpage.global.js
CHANGED
|
@@ -35151,6 +35151,14 @@
|
|
|
35151
35151
|
}
|
|
35152
35152
|
return false;
|
|
35153
35153
|
}
|
|
35154
|
+
function hitAreaForToggleInput(element) {
|
|
35155
|
+
if (element.children.length || element.textContent?.trim())
|
|
35156
|
+
return false;
|
|
35157
|
+
const parent = element.parentElement;
|
|
35158
|
+
if (!parent)
|
|
35159
|
+
return false;
|
|
35160
|
+
return [...parent.children].some((sibling) => sibling.matches('input[type="checkbox" i], input[type="radio" i]'));
|
|
35161
|
+
}
|
|
35154
35162
|
var RULE_DOCS = "https://ngbracket.com/tools/a11y-devtools/docs";
|
|
35155
35163
|
function shortSelector(element) {
|
|
35156
35164
|
const tag = element.tagName.toLowerCase();
|
|
@@ -35202,6 +35210,7 @@
|
|
|
35202
35210
|
const keyCache = /* @__PURE__ */ new Map();
|
|
35203
35211
|
const sharedCache = /* @__PURE__ */ new Map();
|
|
35204
35212
|
const unreachable = /* @__PURE__ */ new Set();
|
|
35213
|
+
const hitAreas = /* @__PURE__ */ new Set();
|
|
35205
35214
|
const listenerEvents = /* @__PURE__ */ new Map();
|
|
35206
35215
|
const eventsOf = (el) => {
|
|
35207
35216
|
let events = listenerEvents.get(el);
|
|
@@ -35260,6 +35269,10 @@
|
|
|
35260
35269
|
if (!focusable) {
|
|
35261
35270
|
if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
|
|
35262
35271
|
continue;
|
|
35272
|
+
if (!interactiveByRole && hitAreaForToggleInput(element)) {
|
|
35273
|
+
hitAreas.add(element);
|
|
35274
|
+
continue;
|
|
35275
|
+
}
|
|
35263
35276
|
const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
|
|
35264
35277
|
if (within === "reached")
|
|
35265
35278
|
continue;
|
|
@@ -35278,7 +35291,7 @@
|
|
|
35278
35291
|
findings.push(make(element, "ngbr/click-without-key", "moderate", `Keyboard users may not be able to activate this: Tab reaches it, but it only listens for click, and Enter and Space don't fire click on a non-native element. Use a <button>, or handle Enter and Space too. Heuristic \u2014 verify manually.`, `${RULE_DOCS}/click-without-key`));
|
|
35279
35292
|
}
|
|
35280
35293
|
}
|
|
35281
|
-
const hoverFlagged = new Set(unreachable);
|
|
35294
|
+
const hoverFlagged = /* @__PURE__ */ new Set([...unreachable, ...hitAreas]);
|
|
35282
35295
|
for (const element of root.querySelectorAll("*")) {
|
|
35283
35296
|
if (modal && !modal.contains(element))
|
|
35284
35297
|
continue;
|
|
@@ -252,6 +252,26 @@ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache)
|
|
|
252
252
|
}
|
|
253
253
|
return false;
|
|
254
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* True when `element` is an empty hit area beside a checkbox or radio input: a
|
|
257
|
+
* larger click or touch target that toggles the input, which the keyboard
|
|
258
|
+
* reaches and operates on its own. Angular Material 15 to 21 draws one in every
|
|
259
|
+
* checkbox and radio button (`.mat-mdc-checkbox-touch-target`,
|
|
260
|
+
* `.mat-mdc-radio-touch-target`, each with a click handler; only 21 also marks
|
|
261
|
+
* it `aria-hidden`). Disabled inputs count too: their hit area does nothing either.
|
|
262
|
+
*
|
|
263
|
+
* Only checkbox and radio inputs: an empty clickable beside a text field or a
|
|
264
|
+
* button (a clear "×" drawn in CSS) is a separate action Tab can't reach, and
|
|
265
|
+
* is still reported.
|
|
266
|
+
*/
|
|
267
|
+
function hitAreaForToggleInput(element) {
|
|
268
|
+
if (element.children.length || element.textContent?.trim())
|
|
269
|
+
return false;
|
|
270
|
+
const parent = element.parentElement;
|
|
271
|
+
if (!parent)
|
|
272
|
+
return false;
|
|
273
|
+
return [...parent.children].some((sibling) => sibling.matches('input[type="checkbox" i], input[type="radio" i]'));
|
|
274
|
+
}
|
|
255
275
|
/**
|
|
256
276
|
* Each rule's page: what the message means, who it affects, exactly what
|
|
257
277
|
* triggers it, how to fix and check it, and the WCAG/APG reference.
|
|
@@ -329,6 +349,8 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
329
349
|
const sharedCache = new Map();
|
|
330
350
|
/** Elements reported as unreachable controls, so the hover check doesn't repeat them. */
|
|
331
351
|
const unreachable = new Set();
|
|
352
|
+
/** Checkbox and radio hit areas, skipped by the hover check too. */
|
|
353
|
+
const hitAreas = new Set();
|
|
332
354
|
/** Angular listener names per element, read once and shared by both passes. */
|
|
333
355
|
const listenerEvents = new Map();
|
|
334
356
|
const eventsOf = (el) => {
|
|
@@ -417,6 +439,11 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
417
439
|
// Only for unreachable elements: one Tab reaches is still checked below.
|
|
418
440
|
if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
|
|
419
441
|
continue;
|
|
442
|
+
// A mouse/touch hit area for the checkbox or radio next to it (Material's touch targets).
|
|
443
|
+
if (!interactiveByRole && hitAreaForToggleInput(element)) {
|
|
444
|
+
hitAreas.add(element);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
420
447
|
const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
|
|
421
448
|
if (within === 'reached')
|
|
422
449
|
continue;
|
|
@@ -446,8 +473,9 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
446
473
|
}
|
|
447
474
|
// Hover-only content: a tooltip, hover listener or icon `title` on something
|
|
448
475
|
// Tab can't reach, so keyboard users may never see what it shows.
|
|
449
|
-
// Seeded with the unreachable controls, so an icon inside one isn't reported
|
|
450
|
-
|
|
476
|
+
// Seeded with the unreachable controls, so an icon inside one isn't reported
|
|
477
|
+
// again, and with the skipped checkbox/radio hit areas.
|
|
478
|
+
const hoverFlagged = new Set([...unreachable, ...hitAreas]);
|
|
451
479
|
for (const element of root.querySelectorAll('*')) {
|
|
452
480
|
if (modal && !modal.contains(element))
|
|
453
481
|
continue;
|
package/dist/report/serve.d.ts
CHANGED
|
@@ -26,8 +26,9 @@ export declare function isServing(url: string): Promise<boolean>;
|
|
|
26
26
|
/**
|
|
27
27
|
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
28
28
|
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
29
|
-
* command exits first or `timeoutMs` passes; the
|
|
30
|
-
* of its output. Always `stop()` the result when
|
|
31
|
-
* SIGINT/SIGTERM stop the server before the
|
|
29
|
+
* command exits first, the Angular build fails, or `timeoutMs` passes; the
|
|
30
|
+
* error includes the last lines of its output. Always `stop()` the result when
|
|
31
|
+
* the scan is done. Until then, SIGINT/SIGTERM stop the server before the
|
|
32
|
+
* process ends.
|
|
32
33
|
*/
|
|
33
34
|
export declare function startDevServer(options: DevServerOptions): Promise<DevServer>;
|
package/dist/report/serve.js
CHANGED
|
@@ -2,6 +2,16 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
/** Lines of dev-server output kept for the error message when it fails to start. */
|
|
3
3
|
const OUTPUT_TAIL = 30;
|
|
4
4
|
const POLL_MS = 500;
|
|
5
|
+
/**
|
|
6
|
+
* What `ng serve` prints when a build fails: the application builder (esbuild),
|
|
7
|
+
* then the older browser builder (webpack). Either way the server keeps watching
|
|
8
|
+
* and never answers, so waiting for the timeout only wastes CI time.
|
|
9
|
+
*/
|
|
10
|
+
const BUILD_FAILED = /Application bundle generation failed|Failed to compile/;
|
|
11
|
+
/** `ng serve` prints this once it has listed the build errors. */
|
|
12
|
+
const WATCHING = /Watch mode enabled/;
|
|
13
|
+
/** After a failed build, how long to keep collecting its error lines (ms). */
|
|
14
|
+
const BUILD_ERRORS_MS = 2000;
|
|
5
15
|
/** True when something at `url` answers with a non-5xx response. */
|
|
6
16
|
export async function isServing(url) {
|
|
7
17
|
try {
|
|
@@ -16,9 +26,10 @@ export async function isServing(url) {
|
|
|
16
26
|
/**
|
|
17
27
|
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
18
28
|
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
19
|
-
* command exits first or `timeoutMs` passes; the
|
|
20
|
-
* of its output. Always `stop()` the result when
|
|
21
|
-
* SIGINT/SIGTERM stop the server before the
|
|
29
|
+
* command exits first, the Angular build fails, or `timeoutMs` passes; the
|
|
30
|
+
* error includes the last lines of its output. Always `stop()` the result when
|
|
31
|
+
* the scan is done. Until then, SIGINT/SIGTERM stop the server before the
|
|
32
|
+
* process ends.
|
|
22
33
|
*/
|
|
23
34
|
export async function startDevServer(options) {
|
|
24
35
|
const { command, url, timeoutMs = 180_000, reuseExisting = true } = options;
|
|
@@ -35,18 +46,43 @@ export async function startDevServer(options) {
|
|
|
35
46
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
36
47
|
});
|
|
37
48
|
const tail = [];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// Set when the build fails; `buildErrorsDone` once its error lines are in.
|
|
50
|
+
let buildFailedAt;
|
|
51
|
+
let buildErrorsDone = false;
|
|
52
|
+
const addLine = (line) => {
|
|
53
|
+
if (!line.trim())
|
|
54
|
+
return;
|
|
55
|
+
options.onOutput?.(line);
|
|
56
|
+
tail.push(line);
|
|
57
|
+
if (tail.length > OUTPUT_TAIL)
|
|
58
|
+
tail.shift();
|
|
59
|
+
const plain = stripAnsi(line);
|
|
60
|
+
if (buildFailedAt === undefined && BUILD_FAILED.test(plain))
|
|
61
|
+
buildFailedAt = Date.now();
|
|
62
|
+
else if (buildFailedAt !== undefined && WATCHING.test(plain))
|
|
63
|
+
buildErrorsDone = true;
|
|
64
|
+
};
|
|
65
|
+
// A chunk can end mid-line, so each stream keeps its unfinished last line
|
|
66
|
+
// until the rest arrives (or the stream ends).
|
|
67
|
+
const lineReader = () => {
|
|
68
|
+
let partial = '';
|
|
69
|
+
return {
|
|
70
|
+
data: (chunk) => {
|
|
71
|
+
const lines = (partial + chunk.toString()).split(/\r?\n/);
|
|
72
|
+
partial = lines.pop() ?? '';
|
|
73
|
+
lines.forEach(addLine);
|
|
74
|
+
},
|
|
75
|
+
end: () => {
|
|
76
|
+
addLine(partial);
|
|
77
|
+
partial = '';
|
|
78
|
+
},
|
|
79
|
+
};
|
|
47
80
|
};
|
|
48
|
-
child.stdout
|
|
49
|
-
|
|
81
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
82
|
+
const reader = lineReader();
|
|
83
|
+
stream?.on('data', reader.data);
|
|
84
|
+
stream?.on('end', reader.end);
|
|
85
|
+
}
|
|
50
86
|
let exitCode;
|
|
51
87
|
const exited = new Promise((done) => {
|
|
52
88
|
child.once('exit', (code, signal) => {
|
|
@@ -91,7 +127,12 @@ export async function startDevServer(options) {
|
|
|
91
127
|
await stop();
|
|
92
128
|
throw withOutput(`Dev server command exited (code ${exitCode}) before ${url} answered: ${command}`);
|
|
93
129
|
}
|
|
94
|
-
if (
|
|
130
|
+
if (buildFailedAt !== undefined &&
|
|
131
|
+
(buildErrorsDone || Date.now() - buildFailedAt >= BUILD_ERRORS_MS)) {
|
|
132
|
+
await stop();
|
|
133
|
+
throw withOutput(`The Angular build failed, so the dev server never started: ${command}`);
|
|
134
|
+
}
|
|
135
|
+
if (buildFailedAt === undefined && (await isServing(url)))
|
|
95
136
|
return { reused: false, stop };
|
|
96
137
|
if (Date.now() >= deadline) {
|
|
97
138
|
await stop();
|
|
@@ -100,6 +141,9 @@ export async function startDevServer(options) {
|
|
|
100
141
|
await Promise.race([exited, new Promise((r) => setTimeout(r, POLL_MS))]);
|
|
101
142
|
}
|
|
102
143
|
}
|
|
144
|
+
function stripAnsi(text) {
|
|
145
|
+
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
|
146
|
+
}
|
|
103
147
|
function killTree(child, signal) {
|
|
104
148
|
if (child.pid === undefined)
|
|
105
149
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Finds accessibility problems in Angular apps and names the component behind each one. A dev overlay, or headless reports for CI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Duncan Faulkner",
|