@ngbracket/a11y-devtools 0.18.6 → 0.20.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,61 @@
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.20.0
7
+
8
+ ### Added
9
+
10
+ - Focus lost between scans. With `keyboard` on, the provider now watches for
11
+ the focused element being removed while focus falls back to the page body,
12
+ so the next Tab starts from the top of the page. Two new heuristic rules
13
+ report it against the component that owned the element, both under WCAG
14
+ 2.4.3 Focus Order:
15
+ - `ngbr/focus-lost-on-rerender`: an `@if` or `@for` re-render removed the
16
+ focused element and nothing moved focus within 150ms. A dialog or menu
17
+ that returns focus to its trigger on close is not reported.
18
+ - `ngbr/focus-lost-on-navigation`: a route change removed the focused
19
+ element with the old view and left focus on the page body.
20
+ - The pill's menu lists the last 5 route changes: where focus went, whether
21
+ the page title changed, and what live regions announced. For example
22
+ "/orders → /orders/42: focus on body, title unchanged, nothing announced".
23
+ A route is the path and query string, plus the hash for hash routing
24
+ (`#/orders`).
25
+ - New provider options. `navigation: false` turns the watching off; it
26
+ follows `keyboard` by default. `focusTarget` is the CSS selector where
27
+ focus is expected after a route change (default
28
+ `'main, [role="main"], h1'`). It only labels the route-change list.
29
+ - `createFocusLossProbe` and `describeNavigation` are exported for use
30
+ outside the provider.
31
+ - Report mode has a new `--navigation` flag (`navigation: true` in
32
+ `scanPages`). After the scan it loads the first route, then moves to each
33
+ next route inside the app in the order given: it focuses a link to the
34
+ route and presses Enter, or changes the URL with `history.pushState` when
35
+ the page has no such link. Each route's report gets a "Route change"
36
+ section, and focus left on the page body is reported as
37
+ `ngbr/focus-lost-on-navigation`. With `--color-scheme both` it runs once.
38
+ A link that loads a new page is skipped with a warning, because that isn't
39
+ a route change inside the app.
40
+ - The ACR worksheet counts `ngbr/focus-lost-on-navigation` as a check for
41
+ 2.4.3 Focus Order when the run used `--navigation`.
42
+ `ngbr/focus-lost-on-rerender` counts only when a report has its findings,
43
+ because only the in-app overlay sees a re-render.
44
+
45
+ ## 0.19.0
46
+
47
+ ### Added
48
+
49
+ - Each finding now links to the WCAG criteria it relates to, in the
50
+ [NgBracket accessibility reference](https://ngbracket.com/reference). The
51
+ console, the Markdown report and the HTML report show a link such as
52
+ "WCAG 1.4.3 Contrast (Minimum)" after the axe rule link, which stays as it
53
+ was. The reference page says what the criterion asks, where Angular apps
54
+ usually fail it and how to check it.
55
+ - Every finding has a new `wcag` field listing the WCAG 2.2 A and AA
56
+ criteria its rule checks, such as `['1.4.3']`, in the JSON report too.
57
+ axe findings take theirs from the rule's tags. axe's best-practice rules
58
+ have none, so they get no link. The tool's own `ngbr/*` rules use the
59
+ criteria on their docs pages, such as `['2.1.2']` for `ngbr/focus-trap`.
60
+
6
61
  ## 0.18.6
7
62
 
8
63
  ### Fixed
package/README.md CHANGED
@@ -33,6 +33,9 @@ Part of the `@ngbracket` Angular tooling family.
33
33
  - Keyboard & Focus Mode: numbers the tab order, adds keyboard findings, shows the
34
34
  Focus preview card (computed role, name and state), and finds keyboard traps by
35
35
  pressing Tab for real.
36
+ - Focus lost between scans: reports a re-render or a route change that removes the
37
+ focused element and leaves focus on the page body, named after the component.
38
+ Report mode checks route changes too, with `--navigation`.
36
39
  - Production weight: does nothing in production builds, and axe-core isn't loaded
37
40
  there.
38
41
 
@@ -140,3 +143,4 @@ ever becomes reachable through a static import.
140
143
  - Re-render a saved JSON report in any format without scanning (`--from`).
141
144
  - Issue-count badge on the pill and a per-component filter in its menu.
142
145
  - Tab order walkthrough in report mode (`--walkthrough`).
146
+ - Focus lost to a re-render or a route change, with a route-change list in the pill menu.
@@ -65,6 +65,11 @@ Options:
65
65
  --walkthrough Also list each route's tab order with every stop's computed
66
66
  role, name, states and component (an approximation, not
67
67
  any one screen reader's output)
68
+ --navigation Also move between the routes inside the app, in the order
69
+ given, by focusing a link and pressing Enter (or with
70
+ history.pushState when there's no link). Records where
71
+ focus went and reports focus left on the page body
72
+ (ngbr/focus-lost-on-navigation). Needs 2 or more routes
68
73
  --color-scheme <s> light | dark | both — scan with the browser emulating that
69
74
  prefers-color-scheme (default light). "both" scans each
70
75
  route twice; dark pages list only issues light doesn't have
@@ -104,6 +109,7 @@ function parseArgs(argv) {
104
109
  case '--keyboard': opts.keyboard = true; break;
105
110
  case '--focus-traps': opts.focusTraps = true; break;
106
111
  case '--walkthrough': opts.walkthrough = true; break;
112
+ case '--navigation': opts.navigation = true; break;
107
113
  case '--color-scheme': opts.colorScheme = next(); break;
108
114
  case '--dark-class': opts.darkClass = next(); break;
109
115
  case '--dark-attribute': opts.darkAttribute = next(); break;
@@ -122,7 +128,7 @@ const opts = parseArgs(process.argv.slice(2));
122
128
  const SCAN_ONLY = {
123
129
  base: '--base', serve: '--serve', serveTimeout: '--serve-timeout', routes: '--route', tags: '--tags',
124
130
  wait: '--wait', frameworkPrefixes: '--framework-prefixes / --no-skip-primitives', keyboard: '--keyboard',
125
- focusTraps: '--focus-traps', walkthrough: '--walkthrough', colorScheme: '--color-scheme', darkClass: '--dark-class',
131
+ focusTraps: '--focus-traps', walkthrough: '--walkthrough', navigation: '--navigation', colorScheme: '--color-scheme', darkClass: '--dark-class',
126
132
  darkAttribute: '--dark-attribute', headed: '--headed',
127
133
  };
128
134
  if (opts.from && !opts.help) {
@@ -165,6 +171,11 @@ if (!opts.out && (formats.has('acr') || formats.has('acr-md'))) {
165
171
  process.exit(2);
166
172
  }
167
173
 
174
+ if (opts.navigation && opts.routes.length < 2) {
175
+ process.stderr.write('--navigation moves from one route to the next: give 2 or more --route\n');
176
+ process.exit(2);
177
+ }
178
+
168
179
  if (opts.colorScheme && !['light', 'dark', 'both'].includes(opts.colorScheme)) {
169
180
  process.stderr.write(`Invalid --color-scheme "${opts.colorScheme}" (use light, dark or both)\n`);
170
181
  process.exit(2);
@@ -251,6 +262,7 @@ if (!report) {
251
262
  keyboard: opts.keyboard,
252
263
  focusTraps: opts.focusTraps,
253
264
  walkthrough: opts.walkthrough,
265
+ navigation: opts.navigation,
254
266
  colorScheme: opts.colorScheme,
255
267
  darkClass: opts.darkClass,
256
268
  darkAttribute,
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ 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, 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
+ export { createFocusLossProbe, describeNavigation, DEFAULT_FOCUS_TARGET, type FocusLossProbe, type FocusLossProbeOptions, type NavigationFocus, type NavigationRecord, } from './navigation/focus-loss.js';
8
9
  export { findUncontainedModals, type UncontainedModal } from './keyboard/focus-trap.js';
9
10
  export { createFocusWalkProbe, detectTabTrap, type FocusObservation, type FocusWalkProbe, type TabWalkVerdict, } from './keyboard/focus-walk.js';
10
11
  export { describeElement, accessibleDescription, ariaStates, type AxDescription, } from './keyboard/accname.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { logFindings } from './report.js';
5
5
  export { resolveOwningComponentName, resolveComponentPath, appComponentFromPath, resolveListenerEvents, DEFAULT_FRAMEWORK_PREFIXES, ngDebug, } from './attribution.js';
6
6
  export { tabSequence, hasFocusableDescendant, isTabbable, isNativelyFocusable, resolvedTabIndex, visualOrderJumps, } from './keyboard/tab-sequence.js';
7
7
  export { scanKeyboard } from './keyboard/keyboard-scan.js';
8
+ export { createFocusLossProbe, describeNavigation, DEFAULT_FOCUS_TARGET, } from './navigation/focus-loss.js';
8
9
  export { findUncontainedModals } from './keyboard/focus-trap.js';
9
10
  export { createFocusWalkProbe, detectTabTrap, } from './keyboard/focus-walk.js';
10
11
  export { describeElement, accessibleDescription, ariaStates, } from './keyboard/accname.js';
@@ -35003,6 +35003,95 @@
35003
35003
  return false;
35004
35004
  }
35005
35005
 
35006
+ // dist/report/wcag.js
35007
+ var WCAG22_A_AA = [
35008
+ { id: "1.1.1", name: "Non-text Content", level: "A", slug: "non-text-content" },
35009
+ { id: "1.2.1", name: "Audio-only and Video-only (Prerecorded)", level: "A", slug: "audio-only-and-video-only-prerecorded" },
35010
+ { id: "1.2.2", name: "Captions (Prerecorded)", level: "A", slug: "captions-prerecorded" },
35011
+ { id: "1.2.3", name: "Audio Description or Media Alternative (Prerecorded)", level: "A", slug: "audio-description-or-media-alternative-prerecorded" },
35012
+ { id: "1.2.4", name: "Captions (Live)", level: "AA", slug: "captions-live" },
35013
+ { id: "1.2.5", name: "Audio Description (Prerecorded)", level: "AA", slug: "audio-description-prerecorded" },
35014
+ { id: "1.3.1", name: "Info and Relationships", level: "A", slug: "info-and-relationships" },
35015
+ { id: "1.3.2", name: "Meaningful Sequence", level: "A", slug: "meaningful-sequence" },
35016
+ { id: "1.3.3", name: "Sensory Characteristics", level: "A", slug: "sensory-characteristics" },
35017
+ { id: "1.3.4", name: "Orientation", level: "AA", slug: "orientation" },
35018
+ { id: "1.3.5", name: "Identify Input Purpose", level: "AA", slug: "identify-input-purpose" },
35019
+ { id: "1.4.1", name: "Use of Color", level: "A", slug: "use-of-color" },
35020
+ { id: "1.4.2", name: "Audio Control", level: "A", slug: "audio-control" },
35021
+ { id: "1.4.3", name: "Contrast (Minimum)", level: "AA", slug: "contrast-minimum" },
35022
+ { id: "1.4.4", name: "Resize Text", level: "AA", slug: "resize-text" },
35023
+ { id: "1.4.5", name: "Images of Text", level: "AA", slug: "images-of-text" },
35024
+ { id: "1.4.10", name: "Reflow", level: "AA", slug: "reflow" },
35025
+ { id: "1.4.11", name: "Non-text Contrast", level: "AA", slug: "non-text-contrast" },
35026
+ { id: "1.4.12", name: "Text Spacing", level: "AA", slug: "text-spacing" },
35027
+ { id: "1.4.13", name: "Content on Hover or Focus", level: "AA", slug: "content-on-hover-or-focus" },
35028
+ { id: "2.1.1", name: "Keyboard", level: "A", slug: "keyboard" },
35029
+ { id: "2.1.2", name: "No Keyboard Trap", level: "A", slug: "no-keyboard-trap" },
35030
+ { id: "2.1.4", name: "Character Key Shortcuts", level: "A", slug: "character-key-shortcuts" },
35031
+ { id: "2.2.1", name: "Timing Adjustable", level: "A", slug: "timing-adjustable" },
35032
+ { id: "2.2.2", name: "Pause, Stop, Hide", level: "A", slug: "pause-stop-hide" },
35033
+ { id: "2.3.1", name: "Three Flashes or Below Threshold", level: "A", slug: "three-flashes-or-below-threshold" },
35034
+ { id: "2.4.1", name: "Bypass Blocks", level: "A", slug: "bypass-blocks" },
35035
+ { id: "2.4.2", name: "Page Titled", level: "A", slug: "page-titled" },
35036
+ { id: "2.4.3", name: "Focus Order", level: "A", slug: "focus-order" },
35037
+ { id: "2.4.4", name: "Link Purpose (In Context)", level: "A", slug: "link-purpose-in-context" },
35038
+ { id: "2.4.5", name: "Multiple Ways", level: "AA", slug: "multiple-ways" },
35039
+ { id: "2.4.6", name: "Headings and Labels", level: "AA", slug: "headings-and-labels" },
35040
+ { id: "2.4.7", name: "Focus Visible", level: "AA", slug: "focus-visible" },
35041
+ { id: "2.4.11", name: "Focus Not Obscured (Minimum)", level: "AA", slug: "focus-not-obscured-minimum" },
35042
+ { id: "2.5.1", name: "Pointer Gestures", level: "A", slug: "pointer-gestures" },
35043
+ { id: "2.5.2", name: "Pointer Cancellation", level: "A", slug: "pointer-cancellation" },
35044
+ { id: "2.5.3", name: "Label in Name", level: "A", slug: "label-in-name" },
35045
+ { id: "2.5.4", name: "Motion Actuation", level: "A", slug: "motion-actuation" },
35046
+ { id: "2.5.7", name: "Dragging Movements", level: "AA", slug: "dragging-movements" },
35047
+ { id: "2.5.8", name: "Target Size (Minimum)", level: "AA", slug: "target-size-minimum" },
35048
+ { id: "3.1.1", name: "Language of Page", level: "A", slug: "language-of-page" },
35049
+ { id: "3.1.2", name: "Language of Parts", level: "AA", slug: "language-of-parts" },
35050
+ { id: "3.2.1", name: "On Focus", level: "A", slug: "on-focus" },
35051
+ { id: "3.2.2", name: "On Input", level: "A", slug: "on-input" },
35052
+ { id: "3.2.3", name: "Consistent Navigation", level: "AA", slug: "consistent-navigation" },
35053
+ { id: "3.2.4", name: "Consistent Identification", level: "AA", slug: "consistent-identification" },
35054
+ { id: "3.2.6", name: "Consistent Help", level: "A", slug: "consistent-help" },
35055
+ { id: "3.3.1", name: "Error Identification", level: "A", slug: "error-identification" },
35056
+ { id: "3.3.2", name: "Labels or Instructions", level: "A", slug: "labels-or-instructions" },
35057
+ { id: "3.3.3", name: "Error Suggestion", level: "AA", slug: "error-suggestion" },
35058
+ { id: "3.3.4", name: "Error Prevention (Legal, Financial, Data)", level: "AA", slug: "error-prevention-legal-financial-data" },
35059
+ { id: "3.3.7", name: "Redundant Entry", level: "A", slug: "redundant-entry" },
35060
+ { id: "3.3.8", name: "Accessible Authentication (Minimum)", level: "AA", slug: "accessible-authentication-minimum" },
35061
+ { id: "4.1.2", name: "Name, Role, Value", level: "A", slug: "name-role-value" },
35062
+ { id: "4.1.3", name: "Status Messages", level: "AA", slug: "status-messages" }
35063
+ ];
35064
+ function understandingUrl(criterion) {
35065
+ return `https://www.w3.org/WAI/WCAG22/Understanding/${criterion.slug}.html`;
35066
+ }
35067
+ function criterionForTag(tag) {
35068
+ const digits = /^wcag(\d{3,4})$/.exec(tag)?.[1];
35069
+ return digits ? BY_DIGITS.get(digits) : void 0;
35070
+ }
35071
+ var BY_DIGITS = new Map(WCAG22_A_AA.map((c) => [c.id.replace(/\./g, ""), c]));
35072
+ var REFERENCE_WCAG_URL = "https://ngbracket.com/reference/wcag";
35073
+ function referenceUrl(criterion) {
35074
+ return `${REFERENCE_WCAG_URL}/${criterion.slug}`;
35075
+ }
35076
+ var NGBR_RULE_CRITERIA = {
35077
+ "ngbr/unreachable-control": ["2.1.1"],
35078
+ "ngbr/click-without-key": ["2.1.1"],
35079
+ "ngbr/hover-only-content": ["2.1.1"],
35080
+ "ngbr/drag-without-keyboard": ["2.1.1", "2.5.7"],
35081
+ "ngbr/tab-order-mismatch": ["2.4.3"],
35082
+ "ngbr/modal-focus-not-contained": ["2.4.3"],
35083
+ "ngbr/focus-trap": ["2.1.2"],
35084
+ "ngbr/focus-lost-on-navigation": ["2.4.3"],
35085
+ "ngbr/focus-lost-on-rerender": ["2.4.3"]
35086
+ };
35087
+ function ngbrRuleCriteria(id) {
35088
+ return [...NGBR_RULE_CRITERIA[id] ?? []];
35089
+ }
35090
+ function findingCriteria(finding) {
35091
+ const ids = new Set(finding.wcag ?? NGBR_RULE_CRITERIA[finding.id] ?? []);
35092
+ return WCAG22_A_AA.filter((c) => ids.has(c.id));
35093
+ }
35094
+
35006
35095
  // dist/keyboard/keyboard-scan.js
35007
35096
  var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
35008
35097
  "button",
@@ -35240,6 +35329,7 @@
35240
35329
  impact,
35241
35330
  help,
35242
35331
  helpUrl,
35332
+ wcag: ngbrRuleCriteria(id),
35243
35333
  component: appComponentFromPath(componentPath, prefixes),
35244
35334
  componentPath,
35245
35335
  directives: resolveDirectiveNames(element),
@@ -35456,6 +35546,7 @@
35456
35546
  impact: shiftTabEscapes ? "moderate" : "serious",
35457
35547
  help: `Keyboard trap: ${where}${reach}.${shift} If this widget deliberately keeps Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise let Tab move focus on. Found by real Tab presses \u2014 verify manually.`,
35458
35548
  helpUrl: FOCUS_TRAP_DOCS,
35549
+ wcag: ngbrRuleCriteria("ngbr/focus-trap"),
35459
35550
  component: appComponentFromPath(componentPath, frameworkPrefixes),
35460
35551
  componentPath,
35461
35552
  directives: resolveDirectiveNames(owner),
@@ -35466,6 +35557,220 @@
35466
35557
  };
35467
35558
  }
35468
35559
 
35560
+ // dist/navigation/focus-loss.js
35561
+ var DEFAULT_FOCUS_TARGET = 'main, [role="main"], h1';
35562
+ var LIVE_REGION = [
35563
+ '[aria-live]:not([aria-live="off"])',
35564
+ '[role="status"]',
35565
+ '[role="alert"]',
35566
+ '[role="log"]',
35567
+ ".cdk-live-announcer-element"
35568
+ ].join(", ");
35569
+ function safeClosest(el, selector) {
35570
+ try {
35571
+ return el.closest(selector);
35572
+ } catch {
35573
+ return null;
35574
+ }
35575
+ }
35576
+ function createFocusLossProbe(doc = document, options = {}) {
35577
+ const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
35578
+ const graceMs = options.graceMs ?? 150;
35579
+ const focusTarget = options.focusTarget ?? DEFAULT_FOCUS_TARGET;
35580
+ const route = options.route ?? (() => location.pathname + location.search + (location.hash.startsWith("#/") ? location.hash : ""));
35581
+ const records = [];
35582
+ const findings = [];
35583
+ const pending = /* @__PURE__ */ new Map();
35584
+ let focused;
35585
+ const focusByRoute = /* @__PURE__ */ new Map();
35586
+ let lastRoute = route();
35587
+ let lastTitle = doc.title;
35588
+ let navigating = false;
35589
+ const announced = [];
35590
+ const ANNOUNCE_WINDOW_MS = 2e3;
35591
+ const ours = (el) => el.closest(`[${OVERLAY_ATTR}]`) !== null;
35592
+ const onBody = (el) => !el || el === doc.body || el === doc.documentElement;
35593
+ function snapshot(element) {
35594
+ const componentPath = resolveComponentPath(element);
35595
+ const ancestors = [];
35596
+ for (let el = element.parentElement; el && el !== doc.body; el = el.parentElement)
35597
+ ancestors.push(el);
35598
+ return {
35599
+ element,
35600
+ ancestors,
35601
+ route: route(),
35602
+ component: appComponentFromPath(componentPath, prefixes),
35603
+ componentPath,
35604
+ directives: resolveDirectiveNames(element),
35605
+ target: shortSelector(element),
35606
+ html: shortHtml(element)
35607
+ };
35608
+ }
35609
+ function later(fn) {
35610
+ let done;
35611
+ const promise = new Promise((resolve) => done = resolve);
35612
+ const timer = setTimeout(() => {
35613
+ try {
35614
+ fn();
35615
+ } finally {
35616
+ pending.delete(promise);
35617
+ done();
35618
+ }
35619
+ }, graceMs);
35620
+ pending.set(promise, { timer, done });
35621
+ }
35622
+ function report(snap, id, help, page, box) {
35623
+ const anchor = box ? snap.ancestors.find((el) => el.isConnected) : void 0;
35624
+ const finding = {
35625
+ id,
35626
+ impact: "moderate",
35627
+ help,
35628
+ helpUrl: `${RULE_DOCS}/${id.slice("ngbr/".length)}`,
35629
+ wcag: ngbrRuleCriteria(id),
35630
+ component: snap.component,
35631
+ componentPath: snap.componentPath,
35632
+ directives: snap.directives,
35633
+ target: snap.target,
35634
+ locator: anchor ? uniqueLocator(anchor) ?? shortSelector(anchor) : void 0,
35635
+ html: snap.html
35636
+ };
35637
+ findings.push(finding);
35638
+ options.onFinding?.(finding, page);
35639
+ }
35640
+ const onFocusIn = (event) => {
35641
+ const el = event.composedPath()[0] ?? event.target;
35642
+ if (!(el instanceof Element) || onBody(el) || ours(el))
35643
+ return;
35644
+ focused = snapshot(el);
35645
+ focusByRoute.set(focused.route, focused);
35646
+ };
35647
+ const onFocusOut = (event) => {
35648
+ if (event.relatedTarget)
35649
+ return;
35650
+ const snap = focused;
35651
+ if (!snap)
35652
+ return;
35653
+ queueMicrotask(() => {
35654
+ if (focused !== snap || !snap.element.isConnected || !onBody(deepActiveElement(doc)))
35655
+ return;
35656
+ focused = void 0;
35657
+ if (focusByRoute.get(snap.route) === snap)
35658
+ focusByRoute.delete(snap.route);
35659
+ });
35660
+ };
35661
+ function checkRemoval() {
35662
+ const snap = focused;
35663
+ if (!snap || snap.element.isConnected)
35664
+ return;
35665
+ focused = void 0;
35666
+ later(() => {
35667
+ if (route() !== snap.route || navigating)
35668
+ return;
35669
+ if (!onBody(deepActiveElement(doc)))
35670
+ return;
35671
+ snap.reported = true;
35672
+ report(snap, "ngbr/focus-lost-on-rerender", `Focus was lost when this element was removed: it had focus, a re-render took it out of the page, and focus fell back to the page body, so the next Tab starts from the top. Move focus to a sensible place before removing it (the next item, the list, or a heading). Heuristic \u2014 verify manually.`, snap.route, true);
35673
+ });
35674
+ }
35675
+ function logAnnouncements(mutations) {
35676
+ const regions = /* @__PURE__ */ new Set();
35677
+ for (const m of mutations) {
35678
+ const el = m.target instanceof Element ? m.target : m.target.parentElement;
35679
+ if (!el || ours(el))
35680
+ continue;
35681
+ const region = safeClosest(el, LIVE_REGION);
35682
+ if (region && !(m.type === "childList" && [...m.addedNodes].some((n) => n === region || n.contains(region)))) {
35683
+ regions.add(region);
35684
+ }
35685
+ }
35686
+ for (const region of regions) {
35687
+ const text = region.textContent?.replace(/\s+/g, " ").trim();
35688
+ if (text)
35689
+ announced.push({ text: text.length > 200 ? `${text.slice(0, 199)}\u2026` : text, time: Date.now() });
35690
+ }
35691
+ if (announced.length > 50)
35692
+ announced.splice(0, announced.length - 50);
35693
+ }
35694
+ const observer = new MutationObserver((mutations) => {
35695
+ logAnnouncements(mutations);
35696
+ checkRemoval();
35697
+ });
35698
+ observer.observe(doc.documentElement, { childList: true, subtree: true, characterData: true });
35699
+ doc.addEventListener("focusin", onFocusIn, true);
35700
+ doc.addEventListener("focusout", onFocusOut, true);
35701
+ const initial = deepActiveElement(doc);
35702
+ if (initial && !onBody(initial) && !ours(initial)) {
35703
+ focused = snapshot(initial);
35704
+ focusByRoute.set(focused.route, focused);
35705
+ }
35706
+ function notifyStable() {
35707
+ if (navigating)
35708
+ return;
35709
+ if (route() === lastRoute) {
35710
+ lastTitle = doc.title;
35711
+ return;
35712
+ }
35713
+ navigating = true;
35714
+ const from = lastRoute;
35715
+ const titleBefore = lastTitle;
35716
+ const before = focusByRoute.get(from);
35717
+ const since = Date.now() - ANNOUNCE_WINDOW_MS;
35718
+ later(() => {
35719
+ navigating = false;
35720
+ const to = route();
35721
+ lastRoute = to;
35722
+ lastTitle = doc.title;
35723
+ for (const key of [...focusByRoute.keys()])
35724
+ if (key !== to)
35725
+ focusByRoute.delete(key);
35726
+ if (to === from)
35727
+ return;
35728
+ const active = deepActiveElement(doc);
35729
+ const lost = onBody(active);
35730
+ const focus = lost ? "body" : active && safeClosest(active, focusTarget) ? "target" : "other";
35731
+ const record = {
35732
+ from,
35733
+ to,
35734
+ focus,
35735
+ focusedTarget: lost || !active ? null : shortSelector(active),
35736
+ focusedComponent: lost || !active ? null : appComponentFromPath(resolveComponentPath(active), prefixes),
35737
+ focusBefore: before?.target ?? null,
35738
+ titleBefore,
35739
+ titleAfter: doc.title,
35740
+ titleChanged: doc.title !== titleBefore,
35741
+ // What was announced from just before the app settled. An announcer may
35742
+ // speak just before the URL updates, so the route isn't checked.
35743
+ announcements: announced.filter((a) => a.time >= since).map((a) => a.text)
35744
+ };
35745
+ announced.length = 0;
35746
+ records.push(record);
35747
+ options.onNavigation?.(record);
35748
+ if (lost && before && !before.element.isConnected && !before.reported) {
35749
+ report(before, "ngbr/focus-lost-on-navigation", `Focus was lost on the route change from ${from} to ${to}: the element that had focus went away with the old view, and focus fell back to the page body, so the next Tab starts from the top and a screen reader may say nothing. Move focus to the new view's heading or main region after navigation. Heuristic \u2014 verify manually.`, to, false);
35750
+ }
35751
+ });
35752
+ }
35753
+ return {
35754
+ notifyStable,
35755
+ async settled() {
35756
+ while (pending.size)
35757
+ await Promise.all([...pending.keys()]);
35758
+ },
35759
+ records: () => [...records],
35760
+ findings: () => [...findings],
35761
+ stop() {
35762
+ observer.disconnect();
35763
+ doc.removeEventListener("focusin", onFocusIn, true);
35764
+ doc.removeEventListener("focusout", onFocusOut, true);
35765
+ for (const { timer, done } of pending.values()) {
35766
+ clearTimeout(timer);
35767
+ done();
35768
+ }
35769
+ pending.clear();
35770
+ }
35771
+ };
35772
+ }
35773
+
35469
35774
  // dist/keyboard/accname.js
35470
35775
  var axePromise;
35471
35776
  function loadAxe() {
@@ -35624,6 +35929,7 @@
35624
35929
  impact: violation.impact ?? null,
35625
35930
  help: violation.help,
35626
35931
  helpUrl: violation.helpUrl,
35932
+ wcag: violation.tags.flatMap((tag) => criterionForTag(tag)?.id ?? []),
35627
35933
  component: appComponentFromPath(componentPath, frameworkPrefixes),
35628
35934
  componentPath,
35629
35935
  directives: element ? resolveDirectiveNames(element) : [],
@@ -35643,6 +35949,7 @@
35643
35949
  globalThis.__ngbA11yScan = run;
35644
35950
  globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
35645
35951
  globalThis.__ngbA11yWalkthrough = (prefixes) => linearWalkthrough(document, { frameworkPrefixes: prefixes });
35952
+ globalThis.__ngbA11yCreateFocusLossProbe = (prefixes) => createFocusLossProbe(document, { frameworkPrefixes: prefixes });
35646
35953
  })();
35647
35954
  /*! Bundled license information:
35648
35955
 
package/dist/inpage.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createFocusWalkProbe } from './keyboard/focus-walk.js';
2
+ import { createFocusLossProbe } from './navigation/focus-loss.js';
2
3
  import { linearWalkthrough } from './keyboard/walkthrough.js';
3
4
  import { scan } from './scan.js';
4
5
  const run = (options, scanOptions) => scan(document, options, scanOptions);
@@ -8,3 +9,6 @@ globalThis.__ngbA11yScan = run;
8
9
  globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
9
10
  // The linear walkthrough: the tab order with each stop's computed role and name.
10
11
  globalThis.__ngbA11yWalkthrough = (prefixes) => linearWalkthrough(document, { frameworkPrefixes: prefixes });
12
+ // The route-change check: the driver moves between routes inside the app and
13
+ // asks the probe what happened to focus each time.
14
+ globalThis.__ngbA11yCreateFocusLossProbe = (prefixes) => createFocusLossProbe(document, { frameworkPrefixes: prefixes });
@@ -48,6 +48,8 @@ export interface FocusWalkProbe {
48
48
  */
49
49
  trapFinding(cycle: readonly number[], shiftTabEscapes: boolean): A11yFinding | null;
50
50
  }
51
+ /** The element that really has focus, through open shadow roots. */
52
+ export declare function deepActiveElement(doc: Document): Element | null;
51
53
  /**
52
54
  * Create the in-page probe. Ids are assigned on first sight and held in page
53
55
  * memory only — the walk never writes to the DOM.
@@ -21,6 +21,7 @@
21
21
  import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, } from '../attribution.js';
22
22
  import { shortHtml, shortSelector } from './keyboard-scan.js';
23
23
  import { tabSequence } from './tab-sequence.js';
24
+ import { ngbrRuleCriteria } from '../report/wcag.js';
24
25
  /**
25
26
  * Classify a Tab walk. Browsers pass focus through `<body>` (null here) when Tab
26
27
  * wraps off the end of the page, so an element seen again *after* a null means
@@ -59,7 +60,7 @@ export function detectTabTrap(observations, collapsible = new Set()) {
59
60
  /** The rule's page: what the message means, how to fix and check it, and WCAG 2.1.2. */
60
61
  const FOCUS_TRAP_DOCS = 'https://ngbracket.com/tools/a11y-devtools/docs/focus-trap';
61
62
  /** The element that really has focus, through open shadow roots. */
62
- function deepActiveElement(doc) {
63
+ export function deepActiveElement(doc) {
63
64
  let active = doc.activeElement;
64
65
  while (active?.shadowRoot?.activeElement)
65
66
  active = active.shadowRoot.activeElement;
@@ -140,6 +141,7 @@ export function createFocusWalkProbe(doc = document, frameworkPrefixes = DEFAULT
140
141
  `Tab (e.g. a code editor), it must tell users how to leave (such as Escape); otherwise ` +
141
142
  `let Tab move focus on. Found by real Tab presses — verify manually.`,
142
143
  helpUrl: FOCUS_TRAP_DOCS,
144
+ wcag: ngbrRuleCriteria('ngbr/focus-trap'),
143
145
  component: appComponentFromPath(componentPath, frameworkPrefixes),
144
146
  componentPath,
145
147
  directives: resolveDirectiveNames(owner),
@@ -17,6 +17,7 @@ import { findUncontainedModals } from './focus-trap.js';
17
17
  import { hoverSignal } from './hover-content.js';
18
18
  import { dragGroups, dragHandles, hasMoveControl } from './drag-drop.js';
19
19
  import { blockingModalDialog } from '../top-layer.js';
20
+ import { ngbrRuleCriteria } from '../report/wcag.js';
20
21
  import { OVERLAY_EXCLUDE_SELECTOR } from '../overlay.js';
21
22
  /** WAI-ARIA roles that make a non-native element behave as an interactive control. */
22
23
  const INTERACTIVE_ROLES = new Set([
@@ -399,6 +400,7 @@ export function scanKeyboard(root = document, options = {}) {
399
400
  impact,
400
401
  help,
401
402
  helpUrl,
403
+ wcag: ngbrRuleCriteria(id),
402
404
  component: appComponentFromPath(componentPath, prefixes),
403
405
  componentPath,
404
406
  directives: resolveDirectiveNames(element),
@@ -0,0 +1,39 @@
1
+ import type { A11yFinding } from '../scan.js';
2
+ import type { NavigationRecord } from './record.js';
3
+ export type { NavigationFocus, NavigationRecord } from './record.js';
4
+ export { describeNavigation } from './record.js';
5
+ export interface FocusLossProbeOptions {
6
+ /** Component-name prefixes to walk past during attribution. */
7
+ frameworkPrefixes?: readonly string[];
8
+ /**
9
+ * How long to wait after a removal or a route change before checking focus,
10
+ * so a dialog or menu that restores focus on close has done so. Default 150ms.
11
+ */
12
+ graceMs?: number;
13
+ /**
14
+ * Where focus is expected to go after a route change. Only used to label the
15
+ * record (`target` / `other`); focus left on `<body>` is the only finding.
16
+ * Default `'main, [role="main"], h1'`.
17
+ */
18
+ focusTarget?: string;
19
+ /** Called with each finding as it happens. */
20
+ onFinding?: (finding: A11yFinding, route: string) => void;
21
+ /** Called with each route change record. */
22
+ onNavigation?: (record: NavigationRecord) => void;
23
+ /** Current route. Defaults to `location.pathname + location.search`. */
24
+ route?: () => string;
25
+ }
26
+ export interface FocusLossProbe {
27
+ /** The host says the app has settled: check for a route change. */
28
+ notifyStable(): void;
29
+ /** Wait until no check is pending (tests and the headless driver). */
30
+ settled(): Promise<void>;
31
+ /** Route changes recorded so far, oldest first. */
32
+ records(): NavigationRecord[];
33
+ /** Findings reported so far, oldest first. */
34
+ findings(): A11yFinding[];
35
+ stop(): void;
36
+ }
37
+ export declare const DEFAULT_FOCUS_TARGET = "main, [role=\"main\"], h1";
38
+ /** Start watching `doc` for focus lost to a removal or a route change. */
39
+ export declare function createFocusLossProbe(doc?: Document, options?: FocusLossProbeOptions): FocusLossProbe;