@ngbracket/a11y-devtools 0.15.4 → 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,23 @@
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
+
6
23
  ## 0.15.4
7
24
 
8
25
  ### Fixed
@@ -34838,7 +34838,7 @@
34838
34838
  return events.some((e) => KEY_EVENTS.includes(e.split(".")[0]));
34839
34839
  }
34840
34840
  var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
34841
- function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map()) {
34841
+ function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map(), sharedCache = /* @__PURE__ */ new Map()) {
34842
34842
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
34843
34843
  if (!widget)
34844
34844
  return false;
@@ -34848,7 +34848,7 @@
34848
34848
  const tabindex = element.getAttribute("tabindex");
34849
34849
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
34850
34850
  return false;
34851
- const enterable = 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
34852
  if (!enterable)
34853
34853
  return false;
34854
34854
  if (!listenersVisible())
@@ -34873,6 +34873,63 @@
34873
34873
  const keyed = (el) => hasKeyEvent(resolveListenerEvents(el));
34874
34874
  return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll("*")].some(keyed);
34875
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
+ }
34876
34933
  function isComponentHost(el, ng) {
34877
34934
  try {
34878
34935
  return ng?.getComponent(el) != null;
@@ -34881,10 +34938,10 @@
34881
34938
  }
34882
34939
  }
34883
34940
  var ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).join(",");
34884
- function partOfKeyboardOperatedWidget(element, isVisible, keyCache) {
34941
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
34885
34942
  const item = element.parentElement?.closest(ITEM_SELECTOR);
34886
34943
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
34887
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache))
34944
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
34888
34945
  return true;
34889
34946
  }
34890
34947
  for (let el = element.parentElement; el; el = el.parentElement) {
@@ -34911,6 +34968,7 @@
34911
34968
  const isVisible = options.isVisible;
34912
34969
  const findings = [];
34913
34970
  const keyCache = /* @__PURE__ */ new Map();
34971
+ const sharedCache = /* @__PURE__ */ new Map();
34914
34972
  const make = (element, id, impact, help, helpUrl) => {
34915
34973
  const componentPath = resolveComponentPath(element);
34916
34974
  return {
@@ -34944,9 +35002,9 @@
34944
35002
  continue;
34945
35003
  const focusable = isTabbable(element, isVisible);
34946
35004
  if (!focusable) {
34947
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache))
35005
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
34948
35006
  continue;
34949
- const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache) : false;
35007
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
34950
35008
  if (within === "reached")
34951
35009
  continue;
34952
35010
  if (within === "no-keys") {
@@ -66,7 +66,7 @@ const COMPOSITE_SELECTOR = ['tablist', 'toolbar', 'menu', 'menubar', 'radiogroup
66
66
  * Key listeners are read through Angular's dev-mode debug API. Without it (a
67
67
  * production build) nothing can be seen, so roving tabindex counts as reached.
68
68
  */
69
- function reachedWithinWidget(element, isVisible, keyCache = new Map()) {
69
+ function reachedWithinWidget(element, isVisible, keyCache = new Map(), sharedCache = new Map()) {
70
70
  const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
71
71
  if (!widget)
72
72
  return false;
@@ -80,7 +80,10 @@ function reachedWithinWidget(element, isVisible, keyCache = new Map()) {
80
80
  const tabindex = element.getAttribute('tabindex');
81
81
  if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
82
82
  return false;
83
- const enterable = 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);
84
87
  if (!enterable)
85
88
  return false;
86
89
  if (!listenersVisible())
@@ -116,6 +119,87 @@ function handlesKeys(widget, controllers) {
116
119
  // Cheapest first; the widget's contents (every cell of a grid) last.
117
120
  return [widget, ...controllers, ...ancestors].some(keyed) || [...widget.querySelectorAll('*')].some(keyed);
118
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
+ }
119
203
  function isComponentHost(el, ng) {
120
204
  try {
121
205
  return ng?.getComponent(el) != null;
@@ -135,11 +219,11 @@ const ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).j
135
219
  * keys. `<body>` is never tabbable, so a page-wide shortcut listener doesn't
136
220
  * count.
137
221
  */
138
- function partOfKeyboardOperatedWidget(element, isVisible, keyCache) {
222
+ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache) {
139
223
  const item = element.parentElement?.closest(ITEM_SELECTOR);
140
224
  if (item?.parentElement?.closest(COMPOSITE_SELECTOR)) {
141
225
  // 'no-keys' too: the item itself is reported, so its parts needn't be.
142
- if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache))
226
+ if (isTabbable(item, isVisible) || reachedWithinWidget(item, isVisible, keyCache, sharedCache))
143
227
  return true;
144
228
  }
145
229
  for (let el = element.parentElement; el; el = el.parentElement) {
@@ -182,6 +266,7 @@ export function scanKeyboard(root = document, options = {}) {
182
266
  const isVisible = options.isVisible;
183
267
  const findings = [];
184
268
  const keyCache = new Map();
269
+ const sharedCache = new Map();
185
270
  const make = (element, id, impact, help, helpUrl) => {
186
271
  const componentPath = resolveComponentPath(element);
187
272
  return {
@@ -226,9 +311,9 @@ export function scanKeyboard(root = document, options = {}) {
226
311
  if (!focusable) {
227
312
  // A click-only part of something the keyboard operates is a mouse shortcut.
228
313
  // Only for unreachable elements: one Tab reaches is still checked below.
229
- if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache))
314
+ if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
230
315
  continue;
231
- const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache) : false;
316
+ const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
232
317
  if (within === 'reached')
233
318
  continue;
234
319
  if (within === 'no-keys') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.15.4",
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",