@ngbracket/a11y-devtools 0.12.0 → 0.12.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 +22 -0
- package/dist/inpage.global.js +7 -3
- package/dist/keyboard/keyboard-scan.d.ts +2 -0
- package/dist/keyboard/keyboard-scan.js +8 -1
- package/dist/provider.d.ts +4 -3
- package/dist/provider.js +42 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.12.1
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **Production builds really drop the devtools now.** axe-core was never loaded
|
|
11
|
+
in production, but the devtools' own code (overlay, pill, menu) still ended up
|
|
12
|
+
in the app's main bundle when the provider was called unconditionally or behind
|
|
13
|
+
a runtime `isDevMode()` check: +28.5 KB raw (+10.4 KB gzipped) in 0.12.0 on the
|
|
14
|
+
admin example. The provider now checks `ngDevMode`, which the Angular CLI sets
|
|
15
|
+
to `false` in production builds, so the whole implementation is tree-shaken:
|
|
16
|
+
+0.2 KB raw (+0.05 KB gzipped). A new test bundles a production-style build
|
|
17
|
+
and checks the overlay, pill, menu and axe-core are all absent.
|
|
18
|
+
- **Rescans after top-layer changes Angular doesn't see.** Pressing Escape
|
|
19
|
+
closes a native `<dialog>` without any Angular event, so the page kept the
|
|
20
|
+
findings from while the modal was open until something else changed. The
|
|
21
|
+
devtools now also rescan when a dialog closes or a popover opens or closes. A
|
|
22
|
+
scan requested while one is running now runs once that one finishes, instead
|
|
23
|
+
of being dropped.
|
|
24
|
+
- **Keyboard findings skip the page behind an open modal `<dialog>`.** The
|
|
25
|
+
browser makes it inert, and axe already skips it, so the keyboard checks no
|
|
26
|
+
longer report `ngbr/unreachable-control` and `ngbr/click-without-key` there.
|
|
27
|
+
|
|
6
28
|
## 0.12.0
|
|
7
29
|
|
|
8
30
|
### Added
|
package/dist/inpage.global.js
CHANGED
|
@@ -34854,7 +34854,11 @@
|
|
|
34854
34854
|
html: shortHtml(element)
|
|
34855
34855
|
};
|
|
34856
34856
|
};
|
|
34857
|
+
const doc = root instanceof Document ? root : root.ownerDocument;
|
|
34858
|
+
const modal = doc ? blockingModalDialog(doc, options.isModal) : null;
|
|
34857
34859
|
for (const element of root.querySelectorAll("*")) {
|
|
34860
|
+
if (modal && !modal.contains(element))
|
|
34861
|
+
continue;
|
|
34858
34862
|
if (isNativelyFocusable(element))
|
|
34859
34863
|
continue;
|
|
34860
34864
|
const role = element.getAttribute("role")?.toLowerCase() ?? "";
|
|
@@ -34876,10 +34880,10 @@
|
|
|
34876
34880
|
findings.push(make(element, "ngbr/click-without-key", "moderate", `Possible keyboard trap: this element has a (click) handler but no keyboard handler (keydown/keyup) and isn't a native button/link, so Enter/Space may not activate it. Verify by hand, then add a key handler or use a <button>.`, KEYBOARD_URL));
|
|
34877
34881
|
}
|
|
34878
34882
|
}
|
|
34879
|
-
for (const
|
|
34880
|
-
findings.push(make(
|
|
34883
|
+
for (const modal2 of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
34884
|
+
findings.push(make(modal2.element, "ngbr/modal-focus-not-contained", "moderate", `Possible missing focus trap: this element has aria-modal="true", but ${modal2.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard user can Tab out of the modal to the page behind. Mark the background inert or trap focus within the dialog. Heuristic \u2014 verify manually.`, DIALOG_MODAL_URL));
|
|
34881
34885
|
}
|
|
34882
|
-
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
34886
|
+
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible, isModal: options.isModal });
|
|
34883
34887
|
for (const jump of visualOrderJumps(stops)) {
|
|
34884
34888
|
const stop = stops[jump];
|
|
34885
34889
|
findings.push(make(stop.element, "ngbr/tab-order-mismatch", "moderate", `Possible tab-order mismatch: Tab reaches this control (stop ${stop.order}) after one that sits below or to the right of it, so focus jumps against the visual reading order. Heuristic \u2014 verify the order makes sense for a sighted keyboard user.`, FOCUS_ORDER_URL));
|
|
@@ -4,6 +4,8 @@ export interface KeyboardScanOptions {
|
|
|
4
4
|
frameworkPrefixes?: readonly string[];
|
|
5
5
|
/** Visibility predicate override (tests); see {@link tabSequence}. */
|
|
6
6
|
isVisible?: (element: Element) => boolean;
|
|
7
|
+
/** Modal-dialog check override (tests; jsdom has no `:modal`). See {@link tabSequence}. */
|
|
8
|
+
isModal?: (element: Element) => boolean;
|
|
7
9
|
}
|
|
8
10
|
/** A short, human CSS-ish selector for our own findings (not an axe target). */
|
|
9
11
|
export declare function shortSelector(element: Element): string;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
|
|
15
15
|
import { hasFocusableDescendant, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
16
16
|
import { findUncontainedModals } from './focus-trap.js';
|
|
17
|
+
import { blockingModalDialog } from '../top-layer.js';
|
|
17
18
|
/** WAI-ARIA roles that make a non-native element behave as an interactive control. */
|
|
18
19
|
const INTERACTIVE_ROLES = new Set([
|
|
19
20
|
'button',
|
|
@@ -79,7 +80,13 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
79
80
|
html: shortHtml(element),
|
|
80
81
|
};
|
|
81
82
|
};
|
|
83
|
+
// While a modal <dialog> is open the page behind it is inert: not reachable,
|
|
84
|
+
// and not something to report on (axe skips it too). Only check the modal.
|
|
85
|
+
const doc = root instanceof Document ? root : root.ownerDocument;
|
|
86
|
+
const modal = doc ? blockingModalDialog(doc, options.isModal) : null;
|
|
82
87
|
for (const element of root.querySelectorAll('*')) {
|
|
88
|
+
if (modal && !modal.contains(element))
|
|
89
|
+
continue;
|
|
83
90
|
// Native controls are keyboard-reachable and activate on Enter/Space on their
|
|
84
91
|
// own, so they can't be the subject of either finding — skip them outright.
|
|
85
92
|
if (isNativelyFocusable(element))
|
|
@@ -123,7 +130,7 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
123
130
|
}
|
|
124
131
|
// Visual-vs-tab-order mismatch: a heuristic over the resolved sequence. Needs
|
|
125
132
|
// real layout, so it no-ops where getBoundingClientRect returns zeros (jsdom).
|
|
126
|
-
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
|
|
133
|
+
const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible, isModal: options.isModal });
|
|
127
134
|
for (const jump of visualOrderJumps(stops)) {
|
|
128
135
|
const stop = stops[jump];
|
|
129
136
|
findings.push(make(stop.element, 'ngbr/tab-order-mismatch', 'moderate', `Possible tab-order mismatch: Tab reaches this control (stop ${stop.order}) after ` +
|
package/dist/provider.d.ts
CHANGED
|
@@ -70,8 +70,9 @@ export interface A11yDevtoolsOptions {
|
|
|
70
70
|
* settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
|
|
71
71
|
* violation against the component that rendered it.
|
|
72
72
|
*
|
|
73
|
-
* In production this is a no-op and axe-core is never loaded
|
|
74
|
-
*
|
|
75
|
-
*
|
|
73
|
+
* In production this is a no-op and axe-core is never loaded. The Angular CLI
|
|
74
|
+
* replaces `ngDevMode` with `false` in production builds, so the check below is
|
|
75
|
+
* constant and the bundler drops the whole implementation — about 0.3 KB is
|
|
76
|
+
* left, even when the provider is called unconditionally.
|
|
76
77
|
*/
|
|
77
78
|
export declare function provideA11yDevtools(options?: A11yDevtoolsOptions): EnvironmentProviders;
|
package/dist/provider.js
CHANGED
|
@@ -12,11 +12,22 @@ import { readStoredSettings, resolveSettings, visibleFindings, writeStoredSettin
|
|
|
12
12
|
* settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
|
|
13
13
|
* violation against the component that rendered it.
|
|
14
14
|
*
|
|
15
|
-
* In production this is a no-op and axe-core is never loaded
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* In production this is a no-op and axe-core is never loaded. The Angular CLI
|
|
16
|
+
* replaces `ngDevMode` with `false` in production builds, so the check below is
|
|
17
|
+
* constant and the bundler drops the whole implementation — about 0.3 KB is
|
|
18
|
+
* left, even when the provider is called unconditionally.
|
|
18
19
|
*/
|
|
19
20
|
export function provideA11yDevtools(options = {}) {
|
|
21
|
+
// In an Angular production build `ngDevMode` is the constant `false`, so this
|
|
22
|
+
// folds to the empty branch and `devtoolsProviders` (overlay, pill, menu,
|
|
23
|
+
// scanning) is never referenced and gets tree-shaken. Keep it a ternary:
|
|
24
|
+
// bundlers fold a constant conditional expression before tree-shaking, but not
|
|
25
|
+
// an `if (…) return` followed by more code.
|
|
26
|
+
return typeof ngDevMode !== 'undefined' && !ngDevMode
|
|
27
|
+
? makeEnvironmentProviders([])
|
|
28
|
+
: devtoolsProviders(options);
|
|
29
|
+
}
|
|
30
|
+
function devtoolsProviders(options) {
|
|
20
31
|
if (!isDevMode()) {
|
|
21
32
|
return makeEnvironmentProviders([]);
|
|
22
33
|
}
|
|
@@ -150,9 +161,14 @@ export function provideA11yDevtools(options = {}) {
|
|
|
150
161
|
document.addEventListener('focusin', onFocusIn, true);
|
|
151
162
|
}
|
|
152
163
|
let scanning = false;
|
|
164
|
+
let rescanQueued = false;
|
|
153
165
|
function scanNow() {
|
|
154
|
-
if (!enabled
|
|
155
|
-
return;
|
|
166
|
+
if (!enabled)
|
|
167
|
+
return;
|
|
168
|
+
if (scanning) {
|
|
169
|
+
rescanQueued = true; // don't stack scans; run one more when this finishes
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
156
172
|
scanning = true;
|
|
157
173
|
runA11yScan(root?.(), { log, logger, axe, frameworkPrefixes, keyboard })
|
|
158
174
|
.then((findings) => {
|
|
@@ -167,8 +183,26 @@ export function provideA11yDevtools(options = {}) {
|
|
|
167
183
|
.catch(() => undefined)
|
|
168
184
|
.finally(() => {
|
|
169
185
|
scanning = false;
|
|
186
|
+
if (rescanQueued) {
|
|
187
|
+
rescanQueued = false;
|
|
188
|
+
scanNow();
|
|
189
|
+
}
|
|
170
190
|
});
|
|
171
191
|
}
|
|
192
|
+
// Some top-layer changes happen outside Angular, so the app never becomes
|
|
193
|
+
// "unstable" and no rescan follows: Escape closing a native <dialog>, or a
|
|
194
|
+
// popover toggled by the browser. Rescan after those too (our own layers'
|
|
195
|
+
// toggles excepted).
|
|
196
|
+
let topLayerTimer;
|
|
197
|
+
const onTopLayerChange = (event) => {
|
|
198
|
+
const target = event.target;
|
|
199
|
+
if (target instanceof Element && target.hasAttribute(OVERLAY_ATTR))
|
|
200
|
+
return;
|
|
201
|
+
clearTimeout(topLayerTimer);
|
|
202
|
+
topLayerTimer = setTimeout(scanNow, debounceMs);
|
|
203
|
+
};
|
|
204
|
+
document.addEventListener('close', onTopLayerChange, true);
|
|
205
|
+
document.addEventListener('toggle', onTopLayerChange, true);
|
|
172
206
|
const subscription = appRef.isStable
|
|
173
207
|
.pipe(filter((stable) => stable), debounceTime(debounceMs))
|
|
174
208
|
.subscribe(scanNow);
|
|
@@ -178,6 +212,9 @@ export function provideA11yDevtools(options = {}) {
|
|
|
178
212
|
document.removeEventListener('focusin', onFocusIn, true);
|
|
179
213
|
if (onKeyDown)
|
|
180
214
|
document.removeEventListener('keydown', onKeyDown, true);
|
|
215
|
+
document.removeEventListener('close', onTopLayerChange, true);
|
|
216
|
+
document.removeEventListener('toggle', onTopLayerChange, true);
|
|
217
|
+
clearTimeout(topLayerTimer);
|
|
181
218
|
pillView?.destroy();
|
|
182
219
|
overlayView?.destroy();
|
|
183
220
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.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",
|