@ngbracket/a11y-devtools 0.15.3 → 0.15.5

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,49 @@
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.15.5
7
+
8
+ ### Fixed
9
+
10
+ - **`ngbr/unreachable-control` accepts one roving tab stop shared by several
11
+ widgets.** A kanban board with a `role="listbox"` per column and a single tab
12
+ stop for the whole board had every card in the other columns reported as
13
+ serious, although Tab reaches the board and the arrow keys cross columns. An
14
+ item is now also reachable when another widget of the same role, inside the
15
+ same component and repeated alongside it (the same element with the same
16
+ classes, as a `@for` over columns renders; Angular's `ng-*` classes and BEM
17
+ `--modifiers` are ignored), has a tabbable item of the same role. So a
18
+ working listbox can't vouch for an unrelated broken one elsewhere in the
19
+ template, and key handling is still required. Development builds only: it
20
+ needs Angular's debug API to find the component, so a production-build scan
21
+ still reports these items. Found on our own docs: 13 false positives → 0.
22
+
23
+ ## 0.15.4
24
+
25
+ ### Fixed
26
+
27
+ - **`ngbr/unreachable-control` checks that arrow keys are handled before
28
+ skipping a roving-tabindex item.** 0.15.2 skipped an item with
29
+ `tabindex="-1"` whenever Tab could get into its composite widget, so a half-built
30
+ tab list (the first tab at `tabindex="0"`, the rest at `-1`, no arrow-key
31
+ handling) passed silently. The item is now skipped only when something handles
32
+ keys: the widget, anything inside it, an element that controls it, or an
33
+ element around it up to and including the nearest component's host (so an app
34
+ shell's shortcut listener doesn't count). When nothing does, it's reported as
35
+ moderate, to verify by hand. Without Angular's dev-mode debug API (a
36
+ production build), listeners can't be read, so these items are still skipped.
37
+ - **Key listeners bound with modifiers now count as key handling.** Angular
38
+ reports `(keydown.enter)` as `keydown.enter`, which wasn't recognised, so
39
+ `ngbr/click-without-key` flagged a control with `(click)`, `(keydown.enter)`
40
+ and `(keydown.space)`: the fix its own docs recommend. The same applies to
41
+ `(keydown.arrowRight)` and friends in the checks above.
42
+ - **The mouse-shortcut skip no longer hides `ngbr/click-without-key`.** 0.15.3's
43
+ skip for click-only parts of a keyboard-operated widget ran before the
44
+ Tab-reachability check, so a click-only element Tab *does* reach, inside such a
45
+ widget, got no finding at all. The skip now applies only to elements Tab can't
46
+ reach.
47
+ - `--from` with `--serve` no longer also names `--base` in its error message.
48
+
6
49
  ## 0.15.3
7
50
 
8
51
  ### Fixed
@@ -111,7 +111,6 @@ function parseArgs(argv) {
111
111
  }
112
112
 
113
113
  const opts = parseArgs(process.argv.slice(2));
114
- if (opts.serve && !opts.base) opts.base = 'http://localhost:4200';
115
114
 
116
115
  // Options that only mean something when scanning — refused with --from, rather
117
116
  // than silently ignored.
@@ -131,6 +130,9 @@ if (opts.from && !opts.help) {
131
130
  }
132
131
  }
133
132
 
133
+ // After the --from check, so --serve alone isn't reported as --base too.
134
+ if (opts.serve && !opts.base) opts.base = 'http://localhost:4200';
135
+
134
136
  if (opts.help || (!opts.from && (!opts.base || opts.routes.length === 0))) {
135
137
  process.stderr.write(USAGE);
136
138
  process.exit(opts.help ? 0 : 1);
@@ -34834,30 +34834,120 @@
34834
34834
  "treeitem"
34835
34835
  ]);
34836
34836
  var KEY_EVENTS = ["keydown", "keyup", "keypress"];
34837
+ function hasKeyEvent(events) {
34838
+ return events.some((e) => KEY_EVENTS.includes(e.split(".")[0]));
34839
+ }
34837
34840
  var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
34838
- function reachedWithinWidget(element, isVisible) {
34841
+ function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map(), sharedCache = /* @__PURE__ */ new Map()) {
34839
34842
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
34840
34843
  if (!widget)
34841
34844
  return false;
34842
34845
  const controllers = widget.id ? [...(widget.ownerDocument ?? document).querySelectorAll("[aria-controls], [aria-owns]")].filter((el) => `${el.getAttribute("aria-controls") ?? ""} ${el.getAttribute("aria-owns") ?? ""}`.split(/\s+/).includes(widget.id)) : [];
34843
34846
  if ([widget, ...controllers].some((el) => el.hasAttribute("aria-activedescendant")))
34844
- return true;
34847
+ return "reached";
34845
34848
  const tabindex = element.getAttribute("tabindex");
34846
34849
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
34847
34850
  return false;
34848
- return isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
34851
+ const enterable = isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible) || sharesRovingStop(widget, element, isVisible, sharedCache);
34852
+ if (!enterable)
34853
+ return false;
34854
+ if (!listenersVisible())
34855
+ return "reached";
34856
+ let keys = keyCache.get(widget);
34857
+ if (keys === void 0)
34858
+ keyCache.set(widget, keys = handlesKeys(widget, controllers));
34859
+ return keys ? "reached" : "no-keys";
34860
+ }
34861
+ function listenersVisible() {
34862
+ return typeof ngDebug()?.getListeners === "function";
34863
+ }
34864
+ function handlesKeys(widget, controllers) {
34865
+ const ng = ngDebug();
34866
+ const body = widget.ownerDocument?.body;
34867
+ const ancestors = [];
34868
+ for (let el = widget.parentElement; el && el !== body; el = el.parentElement) {
34869
+ ancestors.push(el);
34870
+ if (isComponentHost(el, ng))
34871
+ break;
34872
+ }
34873
+ const keyed = (el) => hasKeyEvent(resolveListenerEvents(el));
34874
+ return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll("*")].some(keyed);
34875
+ }
34876
+ function sharesRovingStop(widget, item, isVisible, cache) {
34877
+ const role = item.getAttribute("role") ?? "";
34878
+ let byRole = cache.get(widget);
34879
+ if (!byRole)
34880
+ cache.set(widget, byRole = /* @__PURE__ */ new Map());
34881
+ let result = byRole.get(role);
34882
+ if (result === void 0)
34883
+ byRole.set(role, result = findsRepeatedSiblingStop(widget, item, isVisible));
34884
+ return result;
34885
+ }
34886
+ function findsRepeatedSiblingStop(widget, item, isVisible) {
34887
+ const ng = ngDebug();
34888
+ const widgetRole = widget.getAttribute("role");
34889
+ const itemRole = item.getAttribute("role");
34890
+ if (!ng || !widgetRole || !itemRole)
34891
+ return false;
34892
+ let host = null;
34893
+ for (let el = widget.parentElement; el; el = el.parentElement) {
34894
+ if (isComponentHost(el, ng)) {
34895
+ host = el;
34896
+ break;
34897
+ }
34898
+ }
34899
+ if (!host)
34900
+ return false;
34901
+ for (const other of host.querySelectorAll(`[role="${widgetRole}"] [role="${itemRole}"]`)) {
34902
+ const otherWidget = other.parentElement?.closest(COMPOSITE_SELECTOR);
34903
+ if (!otherWidget || otherWidget === widget || otherWidget.getAttribute("role") !== widgetRole)
34904
+ continue;
34905
+ if (!isTabbable(other, isVisible))
34906
+ continue;
34907
+ if (repeatedSiblings(widget, otherWidget, host))
34908
+ return true;
34909
+ }
34910
+ return false;
34911
+ }
34912
+ function repeatedSiblings(a, b, bound) {
34913
+ if (a.contains(b) || b.contains(a))
34914
+ return false;
34915
+ for (let branchA = a; branchA && branchA !== bound; branchA = branchA.parentElement) {
34916
+ const parent = branchA.parentElement;
34917
+ if (!parent || !parent.contains(b))
34918
+ continue;
34919
+ let branchB = b;
34920
+ while (branchB && branchB.parentElement !== parent)
34921
+ branchB = branchB.parentElement;
34922
+ if (!branchB || branchB === branchA || branchB.tagName !== branchA.tagName)
34923
+ return false;
34924
+ const setA = structuralClasses(branchA);
34925
+ const setB = structuralClasses(branchB);
34926
+ return setA.length > 0 && setA.length === setB.length && setA.every((c) => setB.includes(c));
34927
+ }
34928
+ return false;
34929
+ }
34930
+ function structuralClasses(el) {
34931
+ return [...el.classList].filter((c) => !c.startsWith("ng-") && !c.includes("--")).sort();
34932
+ }
34933
+ function isComponentHost(el, ng) {
34934
+ try {
34935
+ return ng?.getComponent(el) != null;
34936
+ } catch {
34937
+ return false;
34938
+ }
34849
34939
  }
34850
34940
  var ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).join(",");
34851
- function partOfKeyboardOperatedWidget(element, isVisible) {
34941
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
34852
34942
  const item = element.parentElement?.closest(ITEM_SELECTOR);
34853
34943
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
34854
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible))
34944
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
34855
34945
  return true;
34856
34946
  }
34857
34947
  for (let el = element.parentElement; el; el = el.parentElement) {
34858
34948
  if (!isTabbable(el, isVisible))
34859
34949
  continue;
34860
- return resolveListenerEvents(el).some((e) => KEY_EVENTS.includes(e));
34950
+ return hasKeyEvent(resolveListenerEvents(el));
34861
34951
  }
34862
34952
  return false;
34863
34953
  }
@@ -34877,6 +34967,8 @@
34877
34967
  const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
34878
34968
  const isVisible = options.isVisible;
34879
34969
  const findings = [];
34970
+ const keyCache = /* @__PURE__ */ new Map();
34971
+ const sharedCache = /* @__PURE__ */ new Map();
34880
34972
  const make = (element, id, impact, help, helpUrl) => {
34881
34973
  const componentPath = resolveComponentPath(element);
34882
34974
  return {
@@ -34908,17 +35000,22 @@
34908
35000
  continue;
34909
35001
  if (isHidden(element, isVisible))
34910
35002
  continue;
34911
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible))
34912
- continue;
34913
35003
  const focusable = isTabbable(element, isVisible);
34914
35004
  if (!focusable) {
34915
- if (interactiveByRole && reachedWithinWidget(element, isVisible))
35005
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
35006
+ continue;
35007
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
35008
+ if (within === "reached")
34916
35009
  continue;
35010
+ if (within === "no-keys") {
35011
+ findings.push(make(element, "ngbr/unreachable-control", "moderate", `Keyboard users may not be able to reach this item: it has role="${role}" and is out of the tab order, like a roving-tabindex item, but nothing in or around its widget handles keys, so arrow keys may not move to it. Handle the arrow keys, or use aria-activedescendant. Heuristic \u2014 verify manually.`, `${RULE_DOCS}/unreachable-control`));
35012
+ continue;
35013
+ }
34917
35014
  const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
34918
35015
  findings.push(make(element, "ngbr/unreachable-control", "serious", `Keyboard users can't reach this control: it ${reason}, but it isn't a native control and has no tabindex="0", so Tab skips it. Use a <button> or <a href>, or add tabindex="0" and Enter/Space handling.`, `${RULE_DOCS}/unreachable-control`));
34919
35016
  continue;
34920
35017
  }
34921
- const hasKey = events.some((e) => KEY_EVENTS.includes(e));
35018
+ const hasKey = hasKeyEvent(events);
34922
35019
  if (hasClick && !hasKey) {
34923
35020
  findings.push(make(element, "ngbr/click-without-key", "moderate", `Keyboard users may not be able to activate this: Tab reaches it, but it only listens for click, and Enter and Space don't fire click on a non-native element. Use a <button>, or handle Enter and Space too. Heuristic \u2014 verify manually.`, `${RULE_DOCS}/click-without-key`));
34924
35021
  }
@@ -11,7 +11,7 @@
11
11
  * and `tab-order-mismatch` are flagged as candidates to verify by hand, never as
12
12
  * confirmed failures.
13
13
  */
14
- import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
14
+ import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, ngDebug, } from '../attribution.js';
15
15
  import { hasFocusableDescendant, hasTabbableDescendant, isHidden, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
16
16
  import { findUncontainedModals } from './focus-trap.js';
17
17
  import { blockingModalDialog } from '../top-layer.js';
@@ -35,6 +35,14 @@ const INTERACTIVE_ROLES = new Set([
35
35
  'treeitem',
36
36
  ]);
37
37
  const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
38
+ /**
39
+ * True when `events` includes a key event. Angular reports a listener by the name
40
+ * in the template, key modifiers and all (`(keydown.enter)` → `keydown.enter`),
41
+ * so match on the event before the first dot.
42
+ */
43
+ function hasKeyEvent(events) {
44
+ return events.some((e) => KEY_EVENTS.includes(e.split('.')[0]));
45
+ }
38
46
  /**
39
47
  * Composite widgets: Tab reaches the widget once, and arrow keys move between
40
48
  * its items (WAI-ARIA APG "Keyboard navigation inside components").
@@ -43,17 +51,22 @@ const COMPOSITE_SELECTOR = ['tablist', 'toolbar', 'menu', 'menubar', 'radiogroup
43
51
  .map((role) => `[role="${role}"]`)
44
52
  .join(',');
45
53
  /**
46
- * True when `element` is an item that its composite widget reaches with arrow
47
- * keys, so Tab skipping it is correct:
48
- * - **aria-activedescendant**: focus stays on the widget (or on a combobox that
49
- * controls it) and points at the item; or
50
- * - **roving tabindex**: the item has a tabindex (usually -1), so script can
51
- * focus it, and Tab can get into the widget: one of its items is tabbable,
52
- * the widget itself is, or another element controls it (a menu or listbox
53
- * popup, which gets focus when it opens).
54
- * An item with neither, or a widget Tab can't enter at all, is still reported.
54
+ * How a composite widget's item is reached, when Tab skipping it may be correct:
55
+ * - `'reached'`: the keyboard reaches it within the widget —
56
+ * **aria-activedescendant** (focus stays on the widget, or on a combobox that
57
+ * controls it, and points at the item), or **roving tabindex** (the item has a
58
+ * tabindex, usually -1, so script can focus it; Tab can get into the widget —
59
+ * one of its items is tabbable, the widget itself is, or another element
60
+ * controls it, like a menu button — and something handles keys: see
61
+ * {@link handlesKeys}).
62
+ * - `'no-keys'`: set up for roving tabindex, but no key handling was found, so
63
+ * arrow keys may not move to it — the classic half-built tab list.
64
+ * - `false`: not a composite item, or one Tab can't get into / script can't focus.
65
+ *
66
+ * Key listeners are read through Angular's dev-mode debug API. Without it (a
67
+ * production build) nothing can be seen, so roving tabindex counts as reached.
55
68
  */
56
- function reachedWithinWidget(element, isVisible) {
69
+ function reachedWithinWidget(element, isVisible, keyCache = new Map(), sharedCache = new Map()) {
57
70
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
58
71
  if (!widget)
59
72
  return false;
@@ -63,11 +76,137 @@ function reachedWithinWidget(element, isVisible) {
63
76
  .includes(widget.id))
64
77
  : [];
65
78
  if ([widget, ...controllers].some((el) => el.hasAttribute('aria-activedescendant')))
66
- return true;
79
+ return 'reached';
67
80
  const tabindex = element.getAttribute('tabindex');
68
81
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
69
82
  return false;
70
- return isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
83
+ const enterable = isTabbable(widget, isVisible) ||
84
+ controllers.length > 0 ||
85
+ hasTabbableDescendant(widget, isVisible) ||
86
+ sharesRovingStop(widget, element, isVisible, sharedCache);
87
+ if (!enterable)
88
+ return false;
89
+ if (!listenersVisible())
90
+ return 'reached';
91
+ // Same widget, same answer: work it out once per scan, not once per item.
92
+ let keys = keyCache.get(widget);
93
+ if (keys === undefined)
94
+ keyCache.set(widget, (keys = handlesKeys(widget, controllers)));
95
+ return keys ? 'reached' : 'no-keys';
96
+ }
97
+ /** True when Angular's debug API can tell us which listeners an element has. */
98
+ function listenersVisible() {
99
+ return typeof ngDebug()?.getListeners === 'function';
100
+ }
101
+ /**
102
+ * True when something that could move focus between `widget`'s items listens
103
+ * for keys: the widget, an element that controls it, an ancestor up to and
104
+ * including the nearest component host (Angular Material, for one, puts a tab
105
+ * list's keydown on a wrapper around the `role="tablist"`), or anything inside
106
+ * the widget. The walk stops at that host so an app shell's shortcut listener
107
+ * doesn't vouch for every widget below it.
108
+ */
109
+ function handlesKeys(widget, controllers) {
110
+ const ng = ngDebug();
111
+ const body = widget.ownerDocument?.body;
112
+ const ancestors = [];
113
+ for (let el = widget.parentElement; el && el !== body; el = el.parentElement) {
114
+ ancestors.push(el);
115
+ if (isComponentHost(el, ng))
116
+ break;
117
+ }
118
+ const keyed = (el) => hasKeyEvent(resolveListenerEvents(el));
119
+ // Cheapest first; the widget's contents (every cell of a grid) last.
120
+ return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll('*')].some(keyed);
121
+ }
122
+ /**
123
+ * True when `widget` is one of several same-role widgets that share a single
124
+ * roving tab stop: a kanban board with a `role="listbox"` per column and one tab
125
+ * stop for the whole board, where arrow keys cross columns. A column without the
126
+ * current card has no tabbable item of its own, but Tab still reaches the board.
127
+ *
128
+ * Accepted when another widget of the same role holds a tabbable item of the
129
+ * same role, both inside the nearest component host, AND the two are repeated
130
+ * siblings: where their branches meet, each branch is the same element with the
131
+ * same classes (what a `@for` over columns renders), ignoring Angular's own
132
+ * `ng-*` classes and BEM modifiers (`--full`), which vary by state. So a working
133
+ * listbox can't vouch for an unrelated broken one in another part of the same
134
+ * template. Needs Angular's debug API to find the host; without it (a
135
+ * production build) it never applies.
136
+ */
137
+ function sharesRovingStop(widget, item, isVisible, cache) {
138
+ // Per widget AND item role: a menu can mix menuitem and menuitemradio.
139
+ const role = item.getAttribute('role') ?? '';
140
+ let byRole = cache.get(widget);
141
+ if (!byRole)
142
+ cache.set(widget, (byRole = new Map()));
143
+ let result = byRole.get(role);
144
+ if (result === undefined)
145
+ byRole.set(role, (result = findsRepeatedSiblingStop(widget, item, isVisible)));
146
+ return result;
147
+ }
148
+ function findsRepeatedSiblingStop(widget, item, isVisible) {
149
+ const ng = ngDebug();
150
+ const widgetRole = widget.getAttribute('role');
151
+ const itemRole = item.getAttribute('role');
152
+ if (!ng || !widgetRole || !itemRole)
153
+ return false;
154
+ let host = null;
155
+ for (let el = widget.parentElement; el; el = el.parentElement) {
156
+ if (isComponentHost(el, ng)) {
157
+ host = el;
158
+ break;
159
+ }
160
+ }
161
+ if (!host)
162
+ return false;
163
+ for (const other of host.querySelectorAll(`[role="${widgetRole}"] [role="${itemRole}"]`)) {
164
+ const otherWidget = other.parentElement?.closest(COMPOSITE_SELECTOR);
165
+ if (!otherWidget || otherWidget === widget || otherWidget.getAttribute('role') !== widgetRole)
166
+ continue;
167
+ if (!isTabbable(other, isVisible))
168
+ continue;
169
+ if (repeatedSiblings(widget, otherWidget, host))
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+ /**
175
+ * True when `a` and `b` sit in sibling branches of the same kind: below their
176
+ * lowest common ancestor (inside `bound`), the branch holding each is the same
177
+ * tag with the same (non-empty) set of classes, once Angular's `ng-*` classes
178
+ * (e.g. `ng-star-inserted` from the animations module) and BEM modifiers are
179
+ * set aside. Unclassed wrappers never match: the safe direction.
180
+ */
181
+ function repeatedSiblings(a, b, bound) {
182
+ if (a.contains(b) || b.contains(a))
183
+ return false;
184
+ for (let branchA = a; branchA && branchA !== bound; branchA = branchA.parentElement) {
185
+ const parent = branchA.parentElement;
186
+ if (!parent || !parent.contains(b))
187
+ continue;
188
+ let branchB = b;
189
+ while (branchB && branchB.parentElement !== parent)
190
+ branchB = branchB.parentElement;
191
+ if (!branchB || branchB === branchA || branchB.tagName !== branchA.tagName)
192
+ return false;
193
+ const setA = structuralClasses(branchA);
194
+ const setB = structuralClasses(branchB);
195
+ return setA.length > 0 && setA.length === setB.length && setA.every((c) => setB.includes(c));
196
+ }
197
+ return false;
198
+ }
199
+ /** Classes that say what an element is, not its state: no `ng-*`, no BEM `--modifier`. */
200
+ function structuralClasses(el) {
201
+ return [...el.classList].filter((c) => !c.startsWith('ng-') && !c.includes('--')).sort();
202
+ }
203
+ function isComponentHost(el, ng) {
204
+ try {
205
+ return ng?.getComponent(el) != null;
206
+ }
207
+ catch {
208
+ return false;
209
+ }
71
210
  }
72
211
  const ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).join(',');
73
212
  /**
@@ -80,16 +219,17 @@ const ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).j
80
219
  * keys. `<body>` is never tabbable, so a page-wide shortcut listener doesn't
81
220
  * count.
82
221
  */
83
- function partOfKeyboardOperatedWidget(element, isVisible) {
222
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
84
223
  const item = element.parentElement?.closest(ITEM_SELECTOR);
85
224
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
86
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible))
225
+ // 'no-keys' too: the item itself is reported, so its parts needn't be.
226
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
87
227
  return true;
88
228
  }
89
229
  for (let el = element.parentElement; el; el = el.parentElement) {
90
230
  if (!isTabbable(el, isVisible))
91
231
  continue;
92
- return resolveListenerEvents(el).some((e) => KEY_EVENTS.includes(e));
232
+ return hasKeyEvent(resolveListenerEvents(el));
93
233
  }
94
234
  return false;
95
235
  }
@@ -125,6 +265,8 @@ export function scanKeyboard(root = document, options = {}) {
125
265
  const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
126
266
  const isVisible = options.isVisible;
127
267
  const findings = [];
268
+ const keyCache = new Map();
269
+ const sharedCache = new Map();
128
270
  const make = (element, id, impact, help, helpUrl) => {
129
271
  const componentPath = resolveComponentPath(element);
130
272
  return {
@@ -165,12 +307,22 @@ export function scanKeyboard(root = document, options = {}) {
165
307
  // it isn't shown. Check it when it is.
166
308
  if (isHidden(element, isVisible))
167
309
  continue;
168
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible))
169
- continue;
170
310
  const focusable = isTabbable(element, isVisible);
171
311
  if (!focusable) {
172
- if (interactiveByRole && reachedWithinWidget(element, isVisible))
312
+ // A click-only part of something the keyboard operates is a mouse shortcut.
313
+ // Only for unreachable elements: one Tab reaches is still checked below.
314
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
315
+ continue;
316
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
317
+ if (within === 'reached')
318
+ continue;
319
+ if (within === 'no-keys') {
320
+ findings.push(make(element, 'ngbr/unreachable-control', 'moderate', `Keyboard users may not be able to reach this item: it has role="${role}" and is ` +
321
+ `out of the tab order, like a roving-tabindex item, but nothing in or around its ` +
322
+ `widget handles keys, so arrow keys may not move to it. Handle the arrow keys, or ` +
323
+ `use aria-activedescendant. Heuristic — verify manually.`, `${RULE_DOCS}/unreachable-control`));
173
324
  continue;
325
+ }
174
326
  const reason = interactiveByRole ? `has role="${role}"` : 'has a click handler';
175
327
  findings.push(make(element, 'ngbr/unreachable-control', 'serious', `Keyboard users can't reach this control: it ${reason}, but it isn't a native ` +
176
328
  `control and has no tabindex="0", so Tab skips it. Use a <button> or <a href>, ` +
@@ -179,7 +331,7 @@ export function scanKeyboard(root = document, options = {}) {
179
331
  }
180
332
  // Focusable, but a bare (click) never fires on Enter/Space the way a native
181
333
  // button does — so a keyboard user can reach it and still not activate it.
182
- const hasKey = events.some((e) => KEY_EVENTS.includes(e));
334
+ const hasKey = hasKeyEvent(events);
183
335
  if (hasClick && !hasKey) {
184
336
  findings.push(make(element, 'ngbr/click-without-key', 'moderate', `Keyboard users may not be able to activate this: Tab reaches it, but it only ` +
185
337
  `listens for click, and Enter and Space don't fire click on a non-native element. ` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.15.3",
3
+ "version": "0.15.5",
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",