@ngbracket/a11y-devtools 0.16.0 → 0.18.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,74 @@
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.0
7
+
8
+ ### Added
9
+
10
+ - Report mode can list each route's tab order (`--walkthrough`, or
11
+ `walkthrough: true` in `scanPages`). Every tab stop gets a line with its
12
+ computed role, accessible name, states and owning component, for example
13
+ `button "Save" (disabled) — SaveBarComponent`. A stop with no name reads
14
+ `(no accessible name)`, and a positive `tabindex` is flagged. The list is in
15
+ the JSON, Markdown and HTML reports, under a note that it is a computed
16
+ approximation and not the output of any one screen reader. With
17
+ `--color-scheme both` it runs on the light pass only. It stops at 300 stops
18
+ per page; the report gives the real total when it is cut short.
19
+ - The pill shows a count badge: the issues on the page that pass the menu's
20
+ filters, coloured by the most severe of them (green at 0). The switch gets the
21
+ count in words as its description, for example "5 issues of 14 on this page
22
+ match the filters".
23
+ - The pill menu has a **Show component** filter that lists the components with
24
+ issues on the current page, each with its count at the chosen severity.
25
+ Choosing one draws only that component's highlights and updates the badge.
26
+ The choice isn't saved, and it goes back to all components when the path
27
+ changes. A query-string change (`?page=2`) keeps it.
28
+
29
+ ### Changed
30
+
31
+ - The keyboard-layer screenshot in the README is new: the demo's Keyboard
32
+ section with the severity filter at "Serious and above".
33
+
34
+ ## 0.17.0
35
+
36
+ ### Added
37
+
38
+ - New keyboard rule `ngbr/drag-without-keyboard`. It reports a list whose items
39
+ move by drag and drop when the tool finds no keyboard way to move them.
40
+ Angular CDK drag and drop has no keyboard support of its own, so a list of
41
+ rows with `cdkDragHandle` icons is mouse-only unless the app adds one. The
42
+ rule finds drag items by the `cdk-drag` class inside a `cdk-drop-list`, and
43
+ by `draggable="true"` when a parent holds two or more, in any build. It
44
+ reports each list once. It skips a list with a tab stop in or next to it
45
+ whose name says it moves an item ("Move up", "Reorder", an arrow, a Material
46
+ `arrow_upward` icon). Serious when the keyboard can't reach a drag handle of a
47
+ CDK list; moderate for a native `draggable` list. A handle or item with a
48
+ `tabindex` counts as reachable when a drag list on the page has a tab stop,
49
+ as in a board where one card is the tab stop and the arrow keys move to the
50
+ rest. Moderate in a dev build when a handle is reachable but no Angular key
51
+ listener sits on the handle, its item, the list, or the elements up to and
52
+ including the component that holds the list. Maps to WCAG 2.1.1 and
53
+ 2.5.7 in the ACR worksheet.
54
+
55
+ ### Fixed
56
+
57
+ - The tab-order layer now hides the page's tab stops while an Angular Material
58
+ dialog is open. Material 22 opens `mat-dialog` with `aria-modal="false"` by
59
+ default and hides the page from screen readers with `aria-hidden`. The
60
+ scanner only looked for the CDK focus trap around `aria-modal="true"`
61
+ elements, so it missed the trap and numbered the page's stops under the
62
+ dialog as well as the dialog's own. It now finds the trap around any
63
+ `mat-dialog-container`, `.cdk-dialog-container` or dialog role. Report mode
64
+ also no longer counts Tab cycling inside a default `mat-dialog` as a
65
+ `ngbr/focus-trap` finding.
66
+ - The scanner now recognises the focus traps in PrimeNG, ngx-bootstrap and
67
+ ng-bootstrap dialogs. PrimeNG and ngx-bootstrap put their sentinels inside
68
+ the dialog, as its first and last tab stops. ng-bootstrap's modal and
69
+ offcanvas trap Tab with a script and no sentinels, so they're recognised by
70
+ element name. Before, the tab-order layer showed the page's stops under these
71
+ dialogs, and `ngbr/modal-focus-not-contained` reported a leak that wasn't
72
+ there.
73
+
6
74
  ## 0.16.0
7
75
 
8
76
  ### Added
package/README.md CHANGED
@@ -60,11 +60,11 @@ export const appConfig: ApplicationConfig = {
60
60
  };
61
61
  ```
62
62
 
63
- ![Keyboard & Focus Mode over the demo page: numbered tab-order badges (badge 1 in
64
- orange flags a positive tabindex) joined by a connector path, severity-coloured
65
- finding highlights labelled with their owning component (including the ngbr/*
66
- keyboard findings), and the Focus preview card showing the focused button's
67
- computed role, name and states.](./demo/keyboard-layer-2026-09.png)
63
+ ![Keyboard & Focus Mode over the demo page's Keyboard section: numbered tab-order
64
+ badges joined by a dashed path (badge 1 in orange flags a positive tabindex), two
65
+ serious keyboard findings labelled with their owning component, the Focus preview
66
+ card showing the focused Menu button's computed role, name and states, and the a11y
67
+ pill in the corner with a red 5, the count of issues that pass the severity filter.](./demo/keyboard-layer-2026-10.png)
68
68
 
69
69
  In CI (`--serve` starts `ng serve`, waits for it, and stops it after the scan):
70
70
 
@@ -116,12 +116,6 @@ ever becomes reachable through a static import.
116
116
 
117
117
  ## Roadmap
118
118
 
119
- ### Planned
120
-
121
- - A headless "linear walkthrough": the tab sequence as a reading list per route in
122
- report mode. The Focus preview is overlay-only for now.
123
- - Per-component filtering and a violation-count badge.
124
-
125
119
  ### Done
126
120
 
127
121
  - Component attribution: the nearest app-owned component, skipping UI primitives.
@@ -144,3 +138,5 @@ ever becomes reachable through a static import.
144
138
  - Report mode can start the dev server (`--serve`).
145
139
  - ACR evaluation worksheet by WCAG 2.2 A/AA criterion (`--format acr`).
146
140
  - Re-render a saved JSON report in any format without scanning (`--from`).
141
+ - Issue-count badge on the pill and a per-component filter in its menu.
142
+ - Tab order walkthrough in report mode (`--walkthrough`).
@@ -61,6 +61,9 @@ Options:
61
61
  --focus-traps Also walk each route with real Tab presses to find keyboard
62
62
  traps — focus that cycles inside part of the page and
63
63
  never moves on (ngbr/focus-trap). Runs after the scan
64
+ --walkthrough Also list each route's tab order with every stop's computed
65
+ role, name, states and component (an approximation, not
66
+ any one screen reader's output)
64
67
  --color-scheme <s> light | dark | both — scan with the browser emulating that
65
68
  prefers-color-scheme (default light). "both" scans each
66
69
  route twice; dark pages list only issues light doesn't have
@@ -99,6 +102,7 @@ function parseArgs(argv) {
99
102
  case '--no-skip-primitives': opts.frameworkPrefixes = []; break;
100
103
  case '--keyboard': opts.keyboard = true; break;
101
104
  case '--focus-traps': opts.focusTraps = true; break;
105
+ case '--walkthrough': opts.walkthrough = true; break;
102
106
  case '--color-scheme': opts.colorScheme = next(); break;
103
107
  case '--dark-class': opts.darkClass = next(); break;
104
108
  case '--dark-attribute': opts.darkAttribute = next(); break;
@@ -117,7 +121,7 @@ const opts = parseArgs(process.argv.slice(2));
117
121
  const SCAN_ONLY = {
118
122
  base: '--base', serve: '--serve', serveTimeout: '--serve-timeout', routes: '--route', tags: '--tags',
119
123
  wait: '--wait', frameworkPrefixes: '--framework-prefixes / --no-skip-primitives', keyboard: '--keyboard',
120
- focusTraps: '--focus-traps', colorScheme: '--color-scheme', darkClass: '--dark-class',
124
+ focusTraps: '--focus-traps', walkthrough: '--walkthrough', colorScheme: '--color-scheme', darkClass: '--dark-class',
121
125
  darkAttribute: '--dark-attribute', headed: '--headed',
122
126
  };
123
127
  if (opts.from && !opts.help) {
@@ -245,6 +249,7 @@ if (!report) {
245
249
  frameworkPrefixes: opts.frameworkPrefixes,
246
250
  keyboard: opts.keyboard,
247
251
  focusTraps: opts.focusTraps,
252
+ walkthrough: opts.walkthrough,
248
253
  colorScheme: opts.colorScheme,
249
254
  darkClass: opts.darkClass,
250
255
  darkAttribute,
@@ -25518,16 +25518,16 @@
25518
25518
  var headingRole = role && role.includes("heading");
25519
25519
  var ariaHeadingLevel = _getAriaValue(vNode, "aria-level").value;
25520
25520
  var ariaLevel = parseInt(ariaHeadingLevel, 10);
25521
- var _ref118 = vNode.props.nodeName.match(/h(\d)/) || [], _ref119 = _slicedToArray(_ref118, 2), headingLevel = _ref119[1];
25521
+ var _ref118 = vNode.props.nodeName.match(/h(\d)/) || [], _ref119 = _slicedToArray(_ref118, 2), headingLevel2 = _ref119[1];
25522
25522
  if (!headingRole) {
25523
25523
  return -1;
25524
25524
  }
25525
- if (headingLevel && !ariaHeadingLevel) {
25526
- return parseInt(headingLevel, 10);
25525
+ if (headingLevel2 && !ariaHeadingLevel) {
25526
+ return parseInt(headingLevel2, 10);
25527
25527
  }
25528
25528
  if (isNaN(ariaLevel) || ariaLevel < 1) {
25529
- if (headingLevel) {
25530
- return parseInt(headingLevel, 10);
25529
+ if (headingLevel2) {
25530
+ return parseInt(headingLevel2, 10);
25531
25531
  }
25532
25532
  return 2;
25533
25533
  }
@@ -34630,8 +34630,17 @@
34630
34630
  return false;
34631
34631
  return el.getAttribute("aria-hidden") === "true" || el.hasAttribute("data-focus-guard");
34632
34632
  }
34633
+ var SCRIPT_TRAP_SELECTOR = "ngb-modal-window, ngb-offcanvas-panel";
34634
+ var TRAP_CANDIDATE_SELECTOR = [
34635
+ '[aria-modal="true"]',
34636
+ '[role="dialog"]',
34637
+ '[role="alertdialog"]',
34638
+ "mat-dialog-container",
34639
+ ".cdk-dialog-container",
34640
+ SCRIPT_TRAP_SELECTOR
34641
+ ].join(", ");
34633
34642
  function sentinelTrappedModal(root, order) {
34634
- const modals = [...root.querySelectorAll('[aria-modal="true"]')].reverse();
34643
+ const modals = [...root.querySelectorAll(TRAP_CANDIDATE_SELECTOR)].reverse();
34635
34644
  for (const modal of modals) {
34636
34645
  const inside = order.map((el) => modal.contains(el));
34637
34646
  const first = inside.indexOf(true);
@@ -34642,6 +34651,10 @@
34642
34651
  const after = order[last + 1];
34643
34652
  if (before && after && isFocusSentinel(before) && isFocusSentinel(after))
34644
34653
  return modal;
34654
+ if (last > first && isFocusSentinel(order[first]) && isFocusSentinel(order[last]))
34655
+ return modal;
34656
+ if (modal.matches(SCRIPT_TRAP_SELECTOR))
34657
+ return modal;
34645
34658
  }
34646
34659
  return null;
34647
34660
  }
@@ -34945,6 +34958,51 @@
34945
34958
  return null;
34946
34959
  }
34947
34960
 
34961
+ // dist/keyboard/drag-drop.js
34962
+ var DRAG_ITEM_SELECTOR = '.cdk-drop-list .cdk-drag, [draggable="true"]';
34963
+ var DRAG_LIST_SELECTOR = '.cdk-drop-list, [draggable="true"]';
34964
+ var MOVE_NAME = /\b(move|reorder)\b|[↑↓⬆⬇▲▼]|\b(arrow_upward|arrow_downward|keyboard_arrow_up|keyboard_arrow_down)\b|^\s*(up|down|top|bottom|earlier|later)\s*$/i;
34965
+ var CONTROL_SELECTOR = 'button, a[href], [role="button"], [role="menuitem"]';
34966
+ function dragGroups(root, isHidden2) {
34967
+ const groups = /* @__PURE__ */ new Map();
34968
+ for (const item of root.querySelectorAll(DRAG_ITEM_SELECTOR)) {
34969
+ if (item.matches(".cdk-drag-disabled, .cdk-drag-preview, .cdk-drag-placeholder"))
34970
+ continue;
34971
+ if (!item.classList.contains("cdk-drag") && item.parentElement?.closest(".cdk-drag"))
34972
+ continue;
34973
+ const container = item.classList.contains("cdk-drag") ? item.parentElement?.closest(".cdk-drop-list") : item.parentElement;
34974
+ if (!container || container.classList.contains("cdk-drop-list-disabled"))
34975
+ continue;
34976
+ if (isHidden2(item))
34977
+ continue;
34978
+ const items = groups.get(container) ?? [];
34979
+ items.push(item);
34980
+ groups.set(container, items);
34981
+ }
34982
+ return [...groups].map(([container, items]) => ({ container, items, cdk: items[0].classList.contains("cdk-drag") })).filter((group) => group.cdk || group.items.length >= 2);
34983
+ }
34984
+ function dragHandles(item) {
34985
+ const handles = [...item.querySelectorAll(".cdk-drag-handle")].filter((handle) => handle.closest('.cdk-drag, [draggable="true"]') === item);
34986
+ return handles.length > 0 ? handles : [item];
34987
+ }
34988
+ function roughName(element) {
34989
+ const labelledBy = (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).map((id) => id ? element.ownerDocument?.getElementById(id)?.textContent ?? "" : "").join(" ");
34990
+ return [element.getAttribute("aria-label"), labelledBy, element.getAttribute("title"), element.textContent].filter(Boolean).join(" ");
34991
+ }
34992
+ function hasMoveControl(container, isTabbable2) {
34993
+ const siblings = [...container.parentElement?.children ?? []].filter((el) => el !== container && !el.matches(DRAG_LIST_SELECTOR) && !el.querySelector(DRAG_LIST_SELECTOR));
34994
+ for (const scope of [container, ...siblings]) {
34995
+ const controls = [...scope.matches(CONTROL_SELECTOR) ? [scope] : [], ...scope.querySelectorAll(CONTROL_SELECTOR)];
34996
+ for (const control of controls) {
34997
+ if (control.closest(".cdk-drag-handle"))
34998
+ continue;
34999
+ if (MOVE_NAME.test(roughName(control)) && isTabbable2(control))
35000
+ return true;
35001
+ }
35002
+ }
35003
+ return false;
35004
+ }
35005
+
34948
35006
  // dist/keyboard/keyboard-scan.js
34949
35007
  var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
34950
35008
  "button",
@@ -34968,6 +35026,10 @@
34968
35026
  function hasKeyEvent(events) {
34969
35027
  return events.some((e) => KEY_EVENTS.includes(e.split(".")[0]));
34970
35028
  }
35029
+ function hasTabindex(element) {
35030
+ const tabindex = element.getAttribute("tabindex");
35031
+ return tabindex !== null && !Number.isNaN(Number.parseInt(tabindex, 10));
35032
+ }
34971
35033
  var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
34972
35034
  function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map(), sharedCache = /* @__PURE__ */ new Map()) {
34973
35035
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
@@ -35236,6 +35298,51 @@
35236
35298
  hoverFlagged.add(element);
35237
35299
  findings.push(hoverFinding(element, signal));
35238
35300
  }
35301
+ const groups = dragGroups(root, (el) => isHidden(el, isVisible));
35302
+ const startsOf = (container, items) => [
35303
+ .../* @__PURE__ */ new Set([container, ...items.flatMap(dragHandles)])
35304
+ ];
35305
+ const anyTabStop = groups.some(({ container, items }) => startsOf(container, items).some((el) => isTabbable(el, isVisible)));
35306
+ for (const { container, items, cdk } of groups) {
35307
+ if (modal && !modal.contains(container))
35308
+ continue;
35309
+ if (container.closest(OVERLAY_EXCLUDE_SELECTOR))
35310
+ continue;
35311
+ if (hasMoveControl(container, (el) => isTabbable(el, isVisible)))
35312
+ continue;
35313
+ const starts = startsOf(container, items);
35314
+ const reachable = starts.filter((el) => isTabbable(el, isVisible) || anyTabStop && hasTabindex(el) && !isDisabled(el) && !isHidden(el, isVisible));
35315
+ const url = `${RULE_DOCS}/drag-without-keyboard`;
35316
+ const count = items.length === 1 ? "1 item here moves" : `${items.length} items here move`;
35317
+ const fix = `Add buttons that move an item (Move up, Move down), or make each drag handle a button that moves its item with the arrow keys and announces the new position. Buttons also help people who can't drag with a mouse.`;
35318
+ if (reachable.length === 0) {
35319
+ findings.push(make(
35320
+ container,
35321
+ "ngbr/drag-without-keyboard",
35322
+ // Native draggable="true" is weaker evidence of a list to reorder than CDK's.
35323
+ cdk ? "serious" : "moderate",
35324
+ `Keyboard users can't move these items: ${count} by drag and drop, but Tab doesn't reach a drag handle and there's no other control to move them. ${fix} Heuristic \u2014 verify manually.`,
35325
+ url
35326
+ ));
35327
+ continue;
35328
+ }
35329
+ if (!listenersVisible())
35330
+ continue;
35331
+ const ng = ngDebug();
35332
+ const keyed = (start) => {
35333
+ for (let el = start; el && el !== el.ownerDocument?.body; el = el.parentElement) {
35334
+ if (hasKeyEvent(eventsOf(el)))
35335
+ return true;
35336
+ if (!container.contains(el) && isComponentHost(el, ng))
35337
+ break;
35338
+ }
35339
+ return false;
35340
+ };
35341
+ const handlesKeys2 = reachable.some(keyed);
35342
+ if (handlesKeys2)
35343
+ continue;
35344
+ findings.push(make(container, "ngbr/drag-without-keyboard", "moderate", `Keyboard users may not be able to move these items: ${count} by drag and drop, and the keyboard can reach their drag handles, but nothing on them handles keys. ${fix} Heuristic \u2014 verify manually.`, url));
35345
+ }
35239
35346
  for (const modal2 of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
35240
35347
  findings.push(make(modal2.element, "ngbr/modal-focus-not-contained", "moderate", `Keyboard users can Tab out of this modal: it has aria-modal="true", but ${modal2.outsideCount} control(s) outside it can still be reached with Tab. Open it with <dialog>.showModal(), make the rest of the page inert, or trap focus. Heuristic \u2014 verify manually.`, `${RULE_DOCS}/modal-focus-not-contained`));
35241
35348
  }
@@ -35281,7 +35388,7 @@
35281
35388
  }
35282
35389
  function containedByOpenModal(elements) {
35283
35390
  const modalOf = (el) => {
35284
- const aria = el.closest('[aria-modal="true"]');
35391
+ const aria = el.closest('[aria-modal="true"], mat-dialog-container, .cdk-dialog-container');
35285
35392
  if (aria)
35286
35393
  return aria;
35287
35394
  try {
@@ -35346,6 +35453,135 @@
35346
35453
  };
35347
35454
  }
35348
35455
 
35456
+ // dist/keyboard/accname.js
35457
+ var axePromise;
35458
+ function loadAxe() {
35459
+ return axePromise ??= Promise.resolve().then(() => __toESM(require_axe(), 1)).then((m) => m.default ?? m);
35460
+ }
35461
+ async function describeElement(element) {
35462
+ return (await describeElements([element]))[0];
35463
+ }
35464
+ async function describeElements(elements) {
35465
+ if (elements.length === 0)
35466
+ return [];
35467
+ const axe = await loadAxe();
35468
+ const doc = elements[0].ownerDocument ?? document;
35469
+ const computed = elements.map(() => ({ role: null, name: "" }));
35470
+ let didSetup = false;
35471
+ try {
35472
+ axe.setup(doc);
35473
+ didSetup = true;
35474
+ elements.forEach((element, i) => {
35475
+ try {
35476
+ const vnode = axe.utils.getNodeFromTree(element);
35477
+ computed[i] = {
35478
+ role: axe.commons.aria.getRole(element) ?? null,
35479
+ name: vnode ? axe.commons.text.accessibleTextVirtual(vnode) ?? "" : ""
35480
+ };
35481
+ } catch {
35482
+ }
35483
+ });
35484
+ } catch {
35485
+ } finally {
35486
+ if (didSetup) {
35487
+ try {
35488
+ axe.teardown();
35489
+ } catch {
35490
+ }
35491
+ }
35492
+ }
35493
+ return elements.map((element, i) => ({
35494
+ ...computed[i],
35495
+ description: accessibleDescription(element),
35496
+ states: ariaStates(element)
35497
+ }));
35498
+ }
35499
+ function accessibleDescription(element) {
35500
+ const ids = element.getAttribute("aria-describedby");
35501
+ if (ids) {
35502
+ const doc = element.ownerDocument ?? document;
35503
+ const text = ids.split(/\s+/).filter(Boolean).map((id) => doc.getElementById(id)?.textContent?.trim() ?? "").filter(Boolean).join(" ");
35504
+ if (text)
35505
+ return text;
35506
+ }
35507
+ return element.getAttribute("title")?.trim() ?? "";
35508
+ }
35509
+ function isOn(value) {
35510
+ return value !== null && value !== "false" && value !== "undefined";
35511
+ }
35512
+ function ariaStates(element) {
35513
+ const states = [];
35514
+ const attr = (name) => element.getAttribute(name);
35515
+ const expanded = attr("aria-expanded");
35516
+ if (expanded === "true")
35517
+ states.push("expanded");
35518
+ else if (expanded === "false")
35519
+ states.push("collapsed");
35520
+ const checked = attr("aria-checked");
35521
+ if (checked === "true")
35522
+ states.push("checked");
35523
+ else if (checked === "false")
35524
+ states.push("not checked");
35525
+ else if (checked === "mixed")
35526
+ states.push("mixed");
35527
+ else if ("checked" in element && element.checked)
35528
+ states.push("checked");
35529
+ const pressed = attr("aria-pressed");
35530
+ if (pressed === "true")
35531
+ states.push("pressed");
35532
+ else if (pressed === "false")
35533
+ states.push("not pressed");
35534
+ if (attr("aria-selected") === "true")
35535
+ states.push("selected");
35536
+ if (isOn(attr("aria-disabled")) || "disabled" in element && element.disabled) {
35537
+ states.push("disabled");
35538
+ }
35539
+ if (isOn(attr("aria-required")) || "required" in element && element.required) {
35540
+ states.push("required");
35541
+ }
35542
+ if (attr("aria-invalid") === "true")
35543
+ states.push("invalid");
35544
+ if (attr("aria-readonly") === "true")
35545
+ states.push("read only");
35546
+ const current = attr("aria-current");
35547
+ if (isOn(current))
35548
+ states.push(current === "true" ? "current" : `current ${current}`);
35549
+ const haspopup = attr("aria-haspopup");
35550
+ if (isOn(haspopup))
35551
+ states.push(haspopup === "true" ? "has popup" : `has ${haspopup} popup`);
35552
+ const level = attr("aria-level") ?? headingLevel(element);
35553
+ if (level)
35554
+ states.push(`level ${level}`);
35555
+ const posinset = attr("aria-posinset");
35556
+ const setsize = attr("aria-setsize");
35557
+ if (posinset && setsize)
35558
+ states.push(`${posinset} of ${setsize}`);
35559
+ return states;
35560
+ }
35561
+ function headingLevel(element) {
35562
+ const match = /^h([1-6])$/.exec(element.tagName.toLowerCase());
35563
+ return match ? match[1] : null;
35564
+ }
35565
+
35566
+ // dist/keyboard/walkthrough.js
35567
+ var WALKTHROUGH_MAX_STEPS = 300;
35568
+ async function linearWalkthrough(root = document, options = {}) {
35569
+ const stops = tabSequence(root, options);
35570
+ const kept = stops.slice(0, WALKTHROUGH_MAX_STEPS);
35571
+ const described = await describeElements(kept.map((s) => s.element));
35572
+ const steps = kept.map((stop, i) => ({
35573
+ order: stop.order,
35574
+ role: described[i].role,
35575
+ name: described[i].name.replace(/\s+/g, " ").trim(),
35576
+ description: described[i].description,
35577
+ states: described[i].states,
35578
+ tag: stop.element.tagName.toLowerCase(),
35579
+ positive: stop.positive,
35580
+ component: stop.component
35581
+ }));
35582
+ return { steps, total: stops.length };
35583
+ }
35584
+
35349
35585
  // dist/scan.js
35350
35586
  var runChain = Promise.resolve();
35351
35587
  function scan(root = document, options, scanOptions) {
@@ -35393,6 +35629,7 @@
35393
35629
  var run = (options, scanOptions) => scan(document, options, scanOptions);
35394
35630
  globalThis.__ngbA11yScan = run;
35395
35631
  globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
35632
+ globalThis.__ngbA11yWalkthrough = (prefixes) => linearWalkthrough(document, { frameworkPrefixes: prefixes });
35396
35633
  })();
35397
35634
  /*! Bundled license information:
35398
35635
 
package/dist/inpage.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { createFocusWalkProbe } from './keyboard/focus-walk.js';
2
+ import { linearWalkthrough } from './keyboard/walkthrough.js';
2
3
  import { scan } from './scan.js';
3
4
  const run = (options, scanOptions) => scan(document, options, scanOptions);
4
5
  globalThis.__ngbA11yScan = run;
5
6
  // The in-page half of the focus-trap walk: the driver creates a probe, presses
6
7
  // real Tab keys, and asks the probe what has focus after each one.
7
8
  globalThis.__ngbA11yCreateFocusProbe = (prefixes) => createFocusWalkProbe(document, prefixes);
9
+ // The linear walkthrough: the tab order with each stop's computed role and name.
10
+ globalThis.__ngbA11yWalkthrough = (prefixes) => linearWalkthrough(document, { frameworkPrefixes: prefixes });
@@ -31,6 +31,11 @@ export interface AxDescription {
31
31
  * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
32
32
  */
33
33
  export declare function describeElement(element: Element): Promise<AxDescription>;
34
+ /**
35
+ * {@link describeElement} for many elements of one document, building axe's
36
+ * tree once instead of once per element (a page's whole tab order, say).
37
+ */
38
+ export declare function describeElements(elements: readonly Element[]): Promise<AxDescription[]>;
34
39
  /** The accessible description: `aria-describedby` targets' text, else the `title`. */
35
40
  export declare function accessibleDescription(element: Element): string;
36
41
  /**
@@ -26,17 +26,34 @@ function loadAxe() {
26
26
  * built — e.g. a scan is mid-flight — so a focus-follow caller degrades quietly.
27
27
  */
28
28
  export async function describeElement(element) {
29
+ return (await describeElements([element]))[0];
30
+ }
31
+ /**
32
+ * {@link describeElement} for many elements of one document, building axe's
33
+ * tree once instead of once per element (a page's whole tab order, say).
34
+ */
35
+ export async function describeElements(elements) {
36
+ if (elements.length === 0)
37
+ return [];
29
38
  const axe = await loadAxe();
30
- const doc = element.ownerDocument ?? document;
31
- let role = null;
32
- let name = '';
39
+ const doc = elements[0].ownerDocument ?? document;
40
+ const computed = elements.map(() => ({ role: null, name: '' }));
33
41
  let didSetup = false;
34
42
  try {
35
43
  axe.setup(doc);
36
44
  didSetup = true;
37
- const vnode = axe.utils.getNodeFromTree(element);
38
- role = axe.commons.aria.getRole(element) ?? null;
39
- name = vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '';
45
+ elements.forEach((element, i) => {
46
+ try {
47
+ const vnode = axe.utils.getNodeFromTree(element);
48
+ computed[i] = {
49
+ role: axe.commons.aria.getRole(element) ?? null,
50
+ name: vnode ? (axe.commons.text.accessibleTextVirtual(vnode) ?? '') : '',
51
+ };
52
+ }
53
+ catch {
54
+ // Leave this one at role=null / name=''.
55
+ }
56
+ });
40
57
  }
41
58
  catch {
42
59
  // Leave role=null / name='' — axe couldn't build a tree (e.g. run in flight).
@@ -53,7 +70,11 @@ export async function describeElement(element) {
53
70
  }
54
71
  }
55
72
  }
56
- return { role, name, description: accessibleDescription(element), states: ariaStates(element) };
73
+ return elements.map((element, i) => ({
74
+ ...computed[i],
75
+ description: accessibleDescription(element),
76
+ states: ariaStates(element),
77
+ }));
57
78
  }
58
79
  /** The accessible description: `aria-describedby` targets' text, else the `title`. */
59
80
  export function accessibleDescription(element) {
@@ -0,0 +1,45 @@
1
+ /**
2
+ * What marks a list whose items move by drag and drop, and what counts as a
3
+ * keyboard way to move them. The keyboard scan reports such a list when it finds
4
+ * no keyboard way (`ngbr/drag-without-keyboard`): Angular CDK drag-drop has no
5
+ * keyboard support of its own, so a CDK list is mouse-only unless the app adds it.
6
+ *
7
+ * Drag items are recognised by DOM markers that are there in production builds
8
+ * too: the `cdk-drag` class that `cdkDrag` puts on its host (only inside a
9
+ * `cdk-drop-list`; a free-standing `cdkDrag`, such as a draggable dialog title,
10
+ * moves something around the screen and is left out), and an explicit
11
+ * `draggable="true"` (native HTML drag and drop, ngx-drag-drop's `dndDraggable`).
12
+ */
13
+ /** A list of drag items under one container. */
14
+ export interface DragGroup {
15
+ /** The drop list, or the items' parent for native drag and drop. */
16
+ container: Element;
17
+ /** The items that can be dragged now (not disabled, not hidden). */
18
+ items: Element[];
19
+ /** True for CDK drag and drop; false for native `draggable="true"`. */
20
+ cdk: boolean;
21
+ }
22
+ /**
23
+ * The drag lists in `root`, one per container. CDK items group by their
24
+ * `cdk-drop-list`; native ones by their parent, and only when there are at least
25
+ * two (one draggable on its own is more often an image or file chip to drag
26
+ * out of the page than a list to reorder). A disabled list or item (CDK's
27
+ * `cdk-drop-list-disabled` / `cdk-drag-disabled`) and CDK's drag preview and
28
+ * placeholder are left out.
29
+ */
30
+ export declare function dragGroups(root: ParentNode, isHidden: (el: Element) => boolean): DragGroup[];
31
+ /**
32
+ * Where a keyboard user would start a move for `item`: its CDK drag handles that
33
+ * belong to it (not to a nested drag item), or the item itself.
34
+ */
35
+ export declare function dragHandles(item: Element): Element[];
36
+ /**
37
+ * True when there's a control near the list whose name says it moves an item
38
+ * ("Move up", "↓", an `arrow_upward` icon): in the list, or in an element next
39
+ * to it such as a toolbar above it. A sibling that holds another drag list is
40
+ * left out, so one list's Move buttons don't vouch for the list beside it. A
41
+ * drag handle doesn't count, even one named "Reorder": whether it works from the
42
+ * keyboard depends on its key handling, which the scan checks separately.
43
+ * `isTabbable` decides whether the keyboard can reach it.
44
+ */
45
+ export declare function hasMoveControl(container: Element, isTabbable: (el: Element) => boolean): boolean;