@ngbracket/a11y-devtools 0.7.2 → 0.8.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,21 @@
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.8.0
7
+
8
+ ### Added
9
+
10
+ - **Keyboard & Focus Mode — M3 (part 1): missing focus-trap detection.** A new
11
+ `ngbr/modal-focus-not-contained` finding (part of the `keyboard` layer) flags an
12
+ open `aria-modal="true"` whose focus isn't contained — i.e. tabbable elements
13
+ outside the modal are still reachable, so a keyboard user can Tab out to the page
14
+ behind it. Reuses the M1 tab-order machinery (which already drops `inert`/hidden
15
+ subtrees), so a modal that correctly inerts the background is **not** flagged.
16
+ - New public API: `findUncontainedModals` and the `UncontainedModal` type.
17
+ - **Honesty guardrail:** a candidate, labelled "verify manually", never a verdict.
18
+ - The *bad-trap* half of M3 ("you can Tab in but never Tab out") needs real Tab
19
+ key presses to observe and is a headless report-mode (Playwright) follow-up.
20
+
6
21
  ## 0.7.2
7
22
 
8
23
  ### Fixed
package/README.md CHANGED
@@ -184,6 +184,10 @@ It adds:
184
184
  (e.g. a handler added via `hostDirectives`).
185
185
  - `ngbr/tab-order-mismatch` — the tab path jumps against the visual reading order
186
186
  (needs real layout, so it fires in report-mode / a real browser).
187
+ - `ngbr/modal-focus-not-contained` — an open `aria-modal="true"` whose focus isn't
188
+ contained: tabbable elements outside it are still reachable, so a keyboard user
189
+ can Tab out to the page behind. (A modal that correctly marks the background
190
+ `inert` is not flagged, since those elements are no longer tabbable.)
187
191
 
188
192
  ```bash
189
193
  # include the keyboard layer in a report-mode run
@@ -250,7 +254,8 @@ npm run build # tsc -> dist/ (ESM + .d.ts)
250
254
 
251
255
  ## Roadmap
252
256
 
253
- - Keyboard & Focus Mode **M3** — focus-trap *candidate* detection.
257
+ - Keyboard & Focus Mode **M3 (part 2)** — *bad-trap* detection ("you can Tab in but
258
+ never Tab out") via real Tab presses in headless report-mode.
254
259
  - Headless "linear walkthrough" — the tab sequence as an SR-ish reading list per
255
260
  route in report-mode (M2's preview is currently overlay-only).
256
261
  - HTML report + baseline/diff mode for CI.
@@ -261,4 +266,4 @@ directive / `hostDirectives` attribution · configurable framework prefixes · a
261
266
  scan · grouped console reporter · dev-only provider · in-app overlay · headless
262
267
  report mode (CLI + `./report`) · **Keyboard & Focus Mode M1** (tab-order viz +
263
268
  keyboard-reachability findings) · **M2** (focus-follow accessibility-tree preview) ·
264
- CI prod-weight guard.
269
+ **M3 part 1** (missing focus-trap: uncontained `aria-modal`) · CI prod-weight guard.
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ 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 { findUncontainedModals, type UncontainedModal } from './keyboard/focus-trap.js';
8
9
  export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
9
10
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, type A11yOverlay, type OverlayOptions, type AxPanelData, } from './overlay.js';
package/dist/index.js CHANGED
@@ -5,5 +5,6 @@ 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 { findUncontainedModals } from './keyboard/focus-trap.js';
8
9
  export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
9
10
  export { createOverlay, OVERLAY_ATTR, OVERLAY_EXCLUDE_SELECTOR, } from './overlay.js';
@@ -34660,6 +34660,27 @@
34660
34660
  return jumps;
34661
34661
  }
34662
34662
 
34663
+ // dist/keyboard/focus-trap.js
34664
+ function findUncontainedModals(root = document, options = {}) {
34665
+ const stops = tabSequence(root, options);
34666
+ if (stops.length === 0)
34667
+ return [];
34668
+ const results = [];
34669
+ for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
34670
+ let insideCount = 0;
34671
+ let outsideCount = 0;
34672
+ for (const stop of stops) {
34673
+ if (modal.contains(stop.element))
34674
+ insideCount++;
34675
+ else
34676
+ outsideCount++;
34677
+ }
34678
+ if (insideCount > 0 && outsideCount > 0)
34679
+ results.push({ element: modal, insideCount, outsideCount });
34680
+ }
34681
+ return results;
34682
+ }
34683
+
34663
34684
  // dist/keyboard/keyboard-scan.js
34664
34685
  var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
34665
34686
  "button",
@@ -34683,6 +34704,7 @@
34683
34704
  var UNDERSTANDING = "https://www.w3.org/WAI/WCAG22/Understanding";
34684
34705
  var KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
34685
34706
  var FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
34707
+ var DIALOG_MODAL_URL = "https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/";
34686
34708
  function shortSelector(element) {
34687
34709
  const tag = element.tagName.toLowerCase();
34688
34710
  if (element.id)
@@ -34732,6 +34754,9 @@
34732
34754
  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));
34733
34755
  }
34734
34756
  }
34757
+ for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
34758
+ findings.push(make(modal.element, "ngbr/modal-focus-not-contained", "moderate", `Possible missing focus trap: this element has aria-modal="true", but ${modal.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));
34759
+ }
34735
34760
  const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
34736
34761
  for (const jump of visualOrderJumps(stops)) {
34737
34762
  const stop = stops[jump];
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The keyboard layer, part D (M3): focus-trap detection. This first landing does
3
+ * the *missing-trap* half — an open modal that fails to contain focus — because
4
+ * it's deterministic and reuses the M1 tab-order machinery directly. The
5
+ * *bad-trap* half ("you can Tab in but never Tab out") needs real Tab key presses
6
+ * to observe, so it belongs in headless report-mode (Playwright) and is a
7
+ * separate follow-up.
8
+ *
9
+ * HONESTY GUARDRAIL: these are *candidates*, not verdicts — a modal may be
10
+ * intentionally non-modal, so findings say "verify manually".
11
+ */
12
+ import { type TabSequenceOptions } from './tab-sequence.js';
13
+ /** An open `aria-modal` whose focus isn't contained, with the leak counts. */
14
+ export interface UncontainedModal {
15
+ /** The `aria-modal="true"` element. */
16
+ element: Element;
17
+ /** Tabbable stops inside the modal. */
18
+ insideCount: number;
19
+ /** Tabbable stops outside the modal that are still reachable (the leak). */
20
+ outsideCount: number;
21
+ }
22
+ /**
23
+ * Open modals (`aria-modal="true"`) whose focus is **not** contained: while the
24
+ * modal is open, tabbable elements outside it are still reachable, so a keyboard
25
+ * user can Tab out to the page behind. Reuses {@link tabSequence} — which already
26
+ * drops `inert`/hidden/disabled subtrees — so a modal that correctly marks the
27
+ * background `inert` produces no outside stops and is *not* flagged. A modal with
28
+ * no tabbable content of its own is skipped (nothing to trap).
29
+ */
30
+ export declare function findUncontainedModals(root?: ParentNode, options?: TabSequenceOptions): UncontainedModal[];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The keyboard layer, part D (M3): focus-trap detection. This first landing does
3
+ * the *missing-trap* half — an open modal that fails to contain focus — because
4
+ * it's deterministic and reuses the M1 tab-order machinery directly. The
5
+ * *bad-trap* half ("you can Tab in but never Tab out") needs real Tab key presses
6
+ * to observe, so it belongs in headless report-mode (Playwright) and is a
7
+ * separate follow-up.
8
+ *
9
+ * HONESTY GUARDRAIL: these are *candidates*, not verdicts — a modal may be
10
+ * intentionally non-modal, so findings say "verify manually".
11
+ */
12
+ import { tabSequence } from './tab-sequence.js';
13
+ /**
14
+ * Open modals (`aria-modal="true"`) whose focus is **not** contained: while the
15
+ * modal is open, tabbable elements outside it are still reachable, so a keyboard
16
+ * user can Tab out to the page behind. Reuses {@link tabSequence} — which already
17
+ * drops `inert`/hidden/disabled subtrees — so a modal that correctly marks the
18
+ * background `inert` produces no outside stops and is *not* flagged. A modal with
19
+ * no tabbable content of its own is skipped (nothing to trap).
20
+ */
21
+ export function findUncontainedModals(root = document, options = {}) {
22
+ const stops = tabSequence(root, options);
23
+ if (stops.length === 0)
24
+ return [];
25
+ const results = [];
26
+ for (const modal of root.querySelectorAll('[aria-modal="true"]')) {
27
+ let insideCount = 0;
28
+ let outsideCount = 0;
29
+ for (const stop of stops) {
30
+ if (modal.contains(stop.element))
31
+ insideCount++;
32
+ else
33
+ outsideCount++;
34
+ }
35
+ if (insideCount > 0 && outsideCount > 0)
36
+ results.push({ element: modal, insideCount, outsideCount });
37
+ }
38
+ return results;
39
+ }
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
15
15
  import { isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
16
+ import { findUncontainedModals } from './focus-trap.js';
16
17
  /** WAI-ARIA roles that make a non-native element behave as an interactive control. */
17
18
  const INTERACTIVE_ROLES = new Set([
18
19
  'button',
@@ -36,6 +37,7 @@ const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
36
37
  const UNDERSTANDING = 'https://www.w3.org/WAI/WCAG22/Understanding';
37
38
  const KEYBOARD_URL = `${UNDERSTANDING}/keyboard.html`;
38
39
  const FOCUS_ORDER_URL = `${UNDERSTANDING}/focus-order.html`;
40
+ const DIALOG_MODAL_URL = 'https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/';
39
41
  /** A short, human CSS-ish selector for our own findings (not an axe target). */
40
42
  function shortSelector(element) {
41
43
  const tag = element.tagName.toLowerCase();
@@ -104,6 +106,15 @@ export function scanKeyboard(root = document, options = {}) {
104
106
  `activate it. Verify by hand, then add a key handler or use a <button>.`, KEYBOARD_URL));
105
107
  }
106
108
  }
109
+ // Missing focus trap (M3): an open aria-modal whose focus isn't contained.
110
+ // Reuses the tab-order machinery (inert/hidden already excluded), so a modal
111
+ // that correctly inerts the background is not flagged.
112
+ for (const modal of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
113
+ findings.push(make(modal.element, 'ngbr/modal-focus-not-contained', 'moderate', `Possible missing focus trap: this element has aria-modal="true", but ` +
114
+ `${modal.outsideCount} tabbable element(s) outside it are still reachable, so a keyboard ` +
115
+ `user can Tab out of the modal to the page behind. Mark the background inert or trap ` +
116
+ `focus within the dialog. Heuristic — verify manually.`, DIALOG_MODAL_URL));
117
+ }
107
118
  // Visual-vs-tab-order mismatch: a heuristic over the resolved sequence. Needs
108
119
  // real layout, so it no-ops where getBoundingClientRect returns zeros (jsdom).
109
120
  const stops = tabSequence(root, { frameworkPrefixes: prefixes, isVisible });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.7.2",
3
+ "version": "0.8.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",