@ngbracket/a11y-devtools 0.18.0 → 0.18.1

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,19 @@
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.1
7
+
8
+ ### Fixed
9
+
10
+ - `ngbr/unreachable-control` no longer reports the touch target in Angular
11
+ Material 15 to 21 checkboxes and radio buttons
12
+ (`.mat-mdc-checkbox-touch-target`, `.mat-mdc-radio-touch-target`). The
13
+ target is an empty element with a click handler that toggles the native
14
+ input beside it, and Tab reaches that input. The rule now skips an empty
15
+ element with a click listener and no role when its parent holds a checkbox
16
+ or radio input. The same element beside a text field or a button is still
17
+ reported. Material 22 removed the handler, so apps on 22 were not affected.
18
+
6
19
  ## 0.18.0
7
20
 
8
21
  ### Added
@@ -35151,6 +35151,14 @@
35151
35151
  }
35152
35152
  return false;
35153
35153
  }
35154
+ function hitAreaForToggleInput(element) {
35155
+ if (element.children.length || element.textContent?.trim())
35156
+ return false;
35157
+ const parent = element.parentElement;
35158
+ if (!parent)
35159
+ return false;
35160
+ return [...parent.children].some((sibling) => sibling.matches('input[type="checkbox" i], input[type="radio" i]'));
35161
+ }
35154
35162
  var RULE_DOCS = "https://ngbracket.com/tools/a11y-devtools/docs";
35155
35163
  function shortSelector(element) {
35156
35164
  const tag = element.tagName.toLowerCase();
@@ -35202,6 +35210,7 @@
35202
35210
  const keyCache = /* @__PURE__ */ new Map();
35203
35211
  const sharedCache = /* @__PURE__ */ new Map();
35204
35212
  const unreachable = /* @__PURE__ */ new Set();
35213
+ const hitAreas = /* @__PURE__ */ new Set();
35205
35214
  const listenerEvents = /* @__PURE__ */ new Map();
35206
35215
  const eventsOf = (el) => {
35207
35216
  let events = listenerEvents.get(el);
@@ -35260,6 +35269,10 @@
35260
35269
  if (!focusable) {
35261
35270
  if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
35262
35271
  continue;
35272
+ if (!interactiveByRole && hitAreaForToggleInput(element)) {
35273
+ hitAreas.add(element);
35274
+ continue;
35275
+ }
35263
35276
  const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
35264
35277
  if (within === "reached")
35265
35278
  continue;
@@ -35278,7 +35291,7 @@
35278
35291
  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`));
35279
35292
  }
35280
35293
  }
35281
- const hoverFlagged = new Set(unreachable);
35294
+ const hoverFlagged = /* @__PURE__ */ new Set([...unreachable, ...hitAreas]);
35282
35295
  for (const element of root.querySelectorAll("*")) {
35283
35296
  if (modal && !modal.contains(element))
35284
35297
  continue;
@@ -252,6 +252,26 @@ function partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache)
252
252
  }
253
253
  return false;
254
254
  }
255
+ /**
256
+ * True when `element` is an empty hit area beside a checkbox or radio input: a
257
+ * larger click or touch target that toggles the input, which the keyboard
258
+ * reaches and operates on its own. Angular Material 15 to 21 draws one in every
259
+ * checkbox and radio button (`.mat-mdc-checkbox-touch-target`,
260
+ * `.mat-mdc-radio-touch-target`, each with a click handler; only 21 also marks
261
+ * it `aria-hidden`). Disabled inputs count too: their hit area does nothing either.
262
+ *
263
+ * Only checkbox and radio inputs: an empty clickable beside a text field or a
264
+ * button (a clear "×" drawn in CSS) is a separate action Tab can't reach, and
265
+ * is still reported.
266
+ */
267
+ function hitAreaForToggleInput(element) {
268
+ if (element.children.length || element.textContent?.trim())
269
+ return false;
270
+ const parent = element.parentElement;
271
+ if (!parent)
272
+ return false;
273
+ return [...parent.children].some((sibling) => sibling.matches('input[type="checkbox" i], input[type="radio" i]'));
274
+ }
255
275
  /**
256
276
  * Each rule's page: what the message means, who it affects, exactly what
257
277
  * triggers it, how to fix and check it, and the WCAG/APG reference.
@@ -329,6 +349,8 @@ export function scanKeyboard(root = document, options = {}) {
329
349
  const sharedCache = new Map();
330
350
  /** Elements reported as unreachable controls, so the hover check doesn't repeat them. */
331
351
  const unreachable = new Set();
352
+ /** Checkbox and radio hit areas, skipped by the hover check too. */
353
+ const hitAreas = new Set();
332
354
  /** Angular listener names per element, read once and shared by both passes. */
333
355
  const listenerEvents = new Map();
334
356
  const eventsOf = (el) => {
@@ -417,6 +439,11 @@ export function scanKeyboard(root = document, options = {}) {
417
439
  // Only for unreachable elements: one Tab reaches is still checked below.
418
440
  if (!interactiveByRole && partOfKeyboardOperatedWidget(element, isVisible, keyCache, sharedCache))
419
441
  continue;
442
+ // A mouse/touch hit area for the checkbox or radio next to it (Material's touch targets).
443
+ if (!interactiveByRole && hitAreaForToggleInput(element)) {
444
+ hitAreas.add(element);
445
+ continue;
446
+ }
420
447
  const within = interactiveByRole ? reachedWithinWidget(element, isVisible, keyCache, sharedCache) : false;
421
448
  if (within === 'reached')
422
449
  continue;
@@ -446,8 +473,9 @@ export function scanKeyboard(root = document, options = {}) {
446
473
  }
447
474
  // Hover-only content: a tooltip, hover listener or icon `title` on something
448
475
  // Tab can't reach, so keyboard users may never see what it shows.
449
- // Seeded with the unreachable controls, so an icon inside one isn't reported again.
450
- const hoverFlagged = new Set(unreachable);
476
+ // Seeded with the unreachable controls, so an icon inside one isn't reported
477
+ // again, and with the skipped checkbox/radio hit areas.
478
+ const hoverFlagged = new Set([...unreachable, ...hitAreas]);
451
479
  for (const element of root.querySelectorAll('*')) {
452
480
  if (modal && !modal.contains(element))
453
481
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Finds accessibility problems in Angular apps and names the component behind each one. A dev overlay, or headless reports for CI.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",