@ngbracket/a11y-devtools 0.15.8 → 0.17.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.
@@ -16,8 +16,8 @@ import { blockingModalDialog } from '../top-layer.js';
16
16
  /**
17
17
  * A focus-trap sentinel: an empty, script-driven tab stop that sends focus back
18
18
  * into the modal when reached — Angular CDK / Material's `cdk-focus-trap-anchor`
19
- * (`tabindex="0"`, `aria-hidden="true"`), or a `data-focus-guard` element (the
20
- * focus-lock pattern). No text and no child elements, so it isn't real content.
19
+ * (`tabindex="0"`, `aria-hidden="true"`), PrimeNG's `p-hidden-focusable` span,
20
+ * or a `data-focus-guard` element (the focus-lock pattern). No text and no child elements, so it isn't real content.
21
21
  */
22
22
  export function isFocusSentinel(el) {
23
23
  if (el.childElementCount > 0 || (el.textContent ?? '').trim() !== '')
@@ -25,14 +25,41 @@ export function isFocusSentinel(el) {
25
25
  return el.getAttribute('aria-hidden') === 'true' || el.hasAttribute('data-focus-guard');
26
26
  }
27
27
  /**
28
- * The open `aria-modal` whose focus a JS trap keeps in, or null: its stops are
29
- * one unbroken run in `order` with a sentinel directly before and after. The
30
- * browser can reach those sentinels, but the trap sends focus from them back
31
- * into the modal. Checked with real Tab presses on a CDK dialog: from the last
28
+ * Dialogs from libraries that trap Tab with a script and add no sentinels:
29
+ * ng-bootstrap's modal and offcanvas (`ngbFocusTrap`). They're recognised by
30
+ * element name, which is there in production builds too.
31
+ */
32
+ const SCRIPT_TRAP_SELECTOR = 'ngb-modal-window, ngb-offcanvas-panel';
33
+ /**
34
+ * Elements that may hold a JS focus trap: any `aria-modal`, any dialog role, the
35
+ * Angular CDK / Material dialog containers, and {@link SCRIPT_TRAP_SELECTOR}.
36
+ * Material 22 opens `mat-dialog` with `aria-modal="false"` (it hides the page
37
+ * with `aria-hidden` instead), so `aria-modal="true"` alone misses every default
38
+ * Material dialog.
39
+ */
40
+ const TRAP_CANDIDATE_SELECTOR = [
41
+ '[aria-modal="true"]',
42
+ '[role="dialog"]',
43
+ '[role="alertdialog"]',
44
+ 'mat-dialog-container',
45
+ '.cdk-dialog-container',
46
+ SCRIPT_TRAP_SELECTOR,
47
+ ].join(', ');
48
+ /**
49
+ * The open dialog whose focus a JS trap keeps in, or null. Its stops must be one
50
+ * unbroken run in `order`, and one of these holds:
51
+ * - a sentinel sits directly before and after the run, outside the dialog
52
+ * (Angular CDK / Material: the anchors are the dialog container's siblings);
53
+ * - the run starts and ends with a sentinel inside the dialog (PrimeNG's
54
+ * `pFocusTrap` prepends and appends hidden spans; ngx-bootstrap's
55
+ * `modal-container` holds its CDK-style anchors around `.modal-dialog`);
56
+ * - the dialog is one of {@link SCRIPT_TRAP_SELECTOR}.
57
+ * The browser can reach those sentinels, but the trap sends focus from them back
58
+ * into the dialog. Checked with real Tab presses on a CDK dialog: from the last
32
59
  * control, Tab wraps to the first. With several, the last is the topmost.
33
60
  */
34
61
  function sentinelTrappedModal(root, order) {
35
- const modals = [...root.querySelectorAll('[aria-modal="true"]')].reverse();
62
+ const modals = [...root.querySelectorAll(TRAP_CANDIDATE_SELECTOR)].reverse();
36
63
  for (const modal of modals) {
37
64
  const inside = order.map((el) => modal.contains(el));
38
65
  const first = inside.indexOf(true);
@@ -43,6 +70,10 @@ function sentinelTrappedModal(root, order) {
43
70
  const after = order[last + 1];
44
71
  if (before && after && isFocusSentinel(before) && isFocusSentinel(after))
45
72
  return modal;
73
+ if (last > first && isFocusSentinel(order[first]) && isFocusSentinel(order[last]))
74
+ return modal;
75
+ if (modal.matches(SCRIPT_TRAP_SELECTOR))
76
+ return modal;
46
77
  }
47
78
  return null;
48
79
  }
@@ -122,7 +153,7 @@ export function resolvedTabIndex(element) {
122
153
  return Number.isNaN(parsed) ? nativeTabIndex(element) : parsed;
123
154
  }
124
155
  /** True when `element` (or an ancestor) is disabled via a control or `<fieldset disabled>`. */
125
- function isDisabled(element) {
156
+ export function isDisabled(element) {
126
157
  if ('disabled' in element && element.disabled)
127
158
  return true;
128
159
  // A disabled fieldset disables its controls (except those inside its first legend).
package/dist/overlay.js CHANGED
@@ -190,7 +190,7 @@ export function createOverlay(options = {}) {
190
190
  function render(findings) {
191
191
  clear();
192
192
  for (const finding of findings) {
193
- const target = resolveTarget(doc, finding.target);
193
+ const target = resolveTarget(doc, finding.locator ?? finding.target);
194
194
  if (!target)
195
195
  continue; // node gone since the scan (e.g. re-rendered)
196
196
  const box = buildBox(doc, finding);
@@ -31,7 +31,9 @@ export interface A11yDevtoolsOptions {
31
31
  /**
32
32
  * Turn on the **keyboard layer** — the ~2/3 of accessibility axe can't test.
33
33
  * Adds heuristic `ngbr/*` findings (keyboard-unreachable controls,
34
- * click-without-keyboard handlers, tab-order mismatches) to the report, and,
34
+ * click-without-keyboard handlers, hover-only content, drag and drop with no
35
+ * keyboard way, tab-order mismatches)
36
+ * to the report, and,
35
37
  * when `overlay` is on, draws the numbered tab-order path over the page.
36
38
  * Default false.
37
39
  */
@@ -17,6 +17,8 @@ export const ACR_TITLE = 'Evaluation worksheet — not a conformance report';
17
17
  const NGBR_RULES = {
18
18
  'ngbr/unreachable-control': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
19
19
  'ngbr/click-without-key': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
20
+ 'ngbr/hover-only-content': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
21
+ 'ngbr/drag-without-keyboard': { criteria: ['2.1.1', '2.5.7'], ranWhen: 'keyboard' },
20
22
  'ngbr/tab-order-mismatch': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
21
23
  'ngbr/modal-focus-not-contained': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
22
24
  'ngbr/focus-trap': { criteria: ['2.1.2'], ranWhen: 'focusTraps' },
@@ -67,8 +67,9 @@ export interface ScanPagesOptions {
67
67
  frameworkPrefixes?: readonly string[];
68
68
  /**
69
69
  * Also run the keyboard layer in-page — heuristic `ngbr/*` findings for
70
- * keyboard-unreachable controls, click-without-keyboard handlers, and
71
- * tab-order mismatches (the last needs real layout, which headless has).
70
+ * keyboard-unreachable controls, click-without-keyboard handlers, hover-only
71
+ * content, drag and drop with no keyboard way, and tab-order mismatches (the
72
+ * last needs real layout, which headless has).
72
73
  * Default false.
73
74
  */
74
75
  keyboard?: boolean;
package/dist/runner.d.ts CHANGED
@@ -22,8 +22,9 @@ export interface RunOptions {
22
22
  frameworkPrefixes?: readonly string[];
23
23
  /**
24
24
  * Also run the keyboard layer — heuristic `ngbr/*` findings for
25
- * keyboard-unreachable controls, click-without-keyboard handlers, and
26
- * tab-order mismatches. Default false.
25
+ * keyboard-unreachable controls, click-without-keyboard handlers, hover-only
26
+ * content, drag and drop with no keyboard way, and tab-order mismatches.
27
+ * Default false.
27
28
  */
28
29
  keyboard?: boolean;
29
30
  }
package/dist/scan.d.ts CHANGED
@@ -32,6 +32,12 @@ export interface A11yFinding {
32
32
  directives: string[];
33
33
  /** CSS selector axe reported for the node. */
34
34
  target: string;
35
+ /**
36
+ * A selector that matches only this node, when `target` can match others.
37
+ * Set by the keyboard layer; the overlay uses it to find the node. Not part of
38
+ * a finding's identity in a baseline.
39
+ */
40
+ locator?: string;
35
41
  html: string;
36
42
  }
37
43
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.15.8",
3
+ "version": "0.17.0",
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",
@@ -71,15 +71,19 @@
71
71
  "devDependencies": {
72
72
  "esbuild": "^0.28.2",
73
73
  "playwright": "^1.40.0",
74
- "@analogjs/vite-plugin-angular": "^2.7.2",
75
- "@analogjs/vitest-angular": "^2.7.2",
76
- "@angular/build": "^22.1.7",
77
- "@angular/common": "^22.1.5",
78
- "@angular/compiler": "^22.1.5",
79
- "@angular/compiler-cli": "^22.1.5",
80
- "@angular/core": "^22.1.5",
81
- "@angular/platform-browser": "^22.1.5",
82
- "@angular/platform-browser-dynamic": "^22.1.5",
74
+ "@analogjs/vite-plugin-angular": "^2.8.0",
75
+ "@analogjs/vitest-angular": "^2.8.0",
76
+ "@angular/build": "^22.2.1",
77
+ "@angular/cdk": "^22.2.1",
78
+ "@angular/common": "^22.2.1",
79
+ "@angular/compiler": "^22.2.1",
80
+ "@angular/compiler-cli": "^22.2.1",
81
+ "@angular/core": "^22.2.1",
82
+ "@angular/forms": "^22.2.1",
83
+ "@angular/platform-browser": "^22.2.1",
84
+ "@angular/platform-browser-dynamic": "^22.2.1",
85
+ "@emnapi/core": "^1.11.3",
86
+ "@emnapi/runtime": "^1.11.3",
83
87
  "@oxc-project/runtime": "^0.149.0",
84
88
  "@types/node": "^26.5.0",
85
89
  "jsdom": "^30.0.1",