@ngbracket/a11y-devtools 0.15.8 → 0.17.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.
@@ -0,0 +1,95 @@
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
+ const DRAG_ITEM_SELECTOR = '.cdk-drop-list .cdk-drag, [draggable="true"]';
14
+ /** Something that is, or holds, a drag list. */
15
+ const DRAG_LIST_SELECTOR = '.cdk-drop-list, [draggable="true"]';
16
+ /**
17
+ * Names of controls that move an item: "Move up", "Move to top", "Reorder",
18
+ * arrow glyphs, and the Material icon ligatures for up and down arrows. Words
19
+ * such as "up" or "top" count only as the whole name, so "Sign up" or "Back to
20
+ * top" elsewhere near the list doesn't count.
21
+ */
22
+ const 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;
23
+ const CONTROL_SELECTOR = 'button, a[href], [role="button"], [role="menuitem"]';
24
+ /**
25
+ * The drag lists in `root`, one per container. CDK items group by their
26
+ * `cdk-drop-list`; native ones by their parent, and only when there are at least
27
+ * two (one draggable on its own is more often an image or file chip to drag
28
+ * out of the page than a list to reorder). A disabled list or item (CDK's
29
+ * `cdk-drop-list-disabled` / `cdk-drag-disabled`) and CDK's drag preview and
30
+ * placeholder are left out.
31
+ */
32
+ export function dragGroups(root, isHidden) {
33
+ const groups = new Map();
34
+ for (const item of root.querySelectorAll(DRAG_ITEM_SELECTOR)) {
35
+ if (item.matches('.cdk-drag-disabled, .cdk-drag-preview, .cdk-drag-placeholder'))
36
+ continue;
37
+ // A native draggable inside a CDK item (an image or link in a card) moves with the item.
38
+ if (!item.classList.contains('cdk-drag') && item.parentElement?.closest('.cdk-drag'))
39
+ continue;
40
+ // From the parent: an element can be both an item and a drop list (nested lists).
41
+ const container = item.classList.contains('cdk-drag')
42
+ ? item.parentElement?.closest('.cdk-drop-list')
43
+ : item.parentElement;
44
+ if (!container || container.classList.contains('cdk-drop-list-disabled'))
45
+ continue;
46
+ if (isHidden(item))
47
+ continue;
48
+ const items = groups.get(container) ?? [];
49
+ items.push(item);
50
+ groups.set(container, items);
51
+ }
52
+ return [...groups]
53
+ .map(([container, items]) => ({ container, items, cdk: items[0].classList.contains('cdk-drag') }))
54
+ .filter((group) => group.cdk || group.items.length >= 2);
55
+ }
56
+ /**
57
+ * Where a keyboard user would start a move for `item`: its CDK drag handles that
58
+ * belong to it (not to a nested drag item), or the item itself.
59
+ */
60
+ export function dragHandles(item) {
61
+ const handles = [...item.querySelectorAll('.cdk-drag-handle')].filter((handle) => handle.closest('.cdk-drag, [draggable="true"]') === item);
62
+ return handles.length > 0 ? handles : [item];
63
+ }
64
+ /** A rough accessible name for a control: aria-label, title, then its text. */
65
+ function roughName(element) {
66
+ const labelledBy = (element.getAttribute('aria-labelledby') ?? '')
67
+ .split(/\s+/)
68
+ .map((id) => (id ? element.ownerDocument?.getElementById(id)?.textContent ?? '' : ''))
69
+ .join(' ');
70
+ return [element.getAttribute('aria-label'), labelledBy, element.getAttribute('title'), element.textContent]
71
+ .filter(Boolean)
72
+ .join(' ');
73
+ }
74
+ /**
75
+ * True when there's a control near the list whose name says it moves an item
76
+ * ("Move up", "↓", an `arrow_upward` icon): in the list, or in an element next
77
+ * to it such as a toolbar above it. A sibling that holds another drag list is
78
+ * left out, so one list's Move buttons don't vouch for the list beside it. A
79
+ * drag handle doesn't count, even one named "Reorder": whether it works from the
80
+ * keyboard depends on its key handling, which the scan checks separately.
81
+ * `isTabbable` decides whether the keyboard can reach it.
82
+ */
83
+ export function hasMoveControl(container, isTabbable) {
84
+ const siblings = [...(container.parentElement?.children ?? [])].filter((el) => el !== container && !el.matches(DRAG_LIST_SELECTOR) && !el.querySelector(DRAG_LIST_SELECTOR));
85
+ for (const scope of [container, ...siblings]) {
86
+ const controls = [...(scope.matches(CONTROL_SELECTOR) ? [scope] : []), ...scope.querySelectorAll(CONTROL_SELECTOR)];
87
+ for (const control of controls) {
88
+ if (control.closest('.cdk-drag-handle'))
89
+ continue;
90
+ if (MOVE_NAME.test(roughName(control)) && isTabbable(control))
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
@@ -68,7 +68,10 @@ function deepActiveElement(doc) {
68
68
  /** True when focus cycling among `elements` is an open modal containing focus (fine). */
69
69
  function containedByOpenModal(elements) {
70
70
  const modalOf = (el) => {
71
- const aria = el.closest('[aria-modal="true"]');
71
+ // CDK / Material dialog containers trap focus by design, even with
72
+ // aria-modal="false" (Material's default). This trusts the container, so a
73
+ // hand-built .cdk-dialog-container with no trap that leaks focus isn't flagged.
74
+ const aria = el.closest('[aria-modal="true"], mat-dialog-container, .cdk-dialog-container');
72
75
  if (aria)
73
76
  return aria;
74
77
  try {
@@ -0,0 +1,14 @@
1
+ /** How an element shows content on hover. */
2
+ export type HoverSignal = 'tooltip' | 'hover-listener' | 'title';
3
+ /**
4
+ * True when `element` shows no text of its own: no text content, an `<svg>` or
5
+ * `<img>`, or an icon-font element whose text is a ligature (`<mat-icon>info</mat-icon>`).
6
+ */
7
+ export declare function isIconLike(element: Element): boolean;
8
+ /**
9
+ * The strongest hover signal on `element`: a tooltip that's switched on, then an
10
+ * Angular hover listener, then a `title` on an icon. `events` are the Angular
11
+ * listener names on it (see `resolveListenerEvents`), passed in so a scan reads
12
+ * them once.
13
+ */
14
+ export declare function hoverSignal(element: Element, events: readonly string[]): HoverSignal | null;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * What marks an element as showing content on hover: a tooltip directive from a
3
+ * known library, an Angular hover listener, or a native `title` on an icon. The
4
+ * keyboard scan reports such an element when Tab can't reach it, since keyboard
5
+ * users then never see that content (`ngbr/hover-only-content`).
6
+ *
7
+ * Tooltip libraries attach their mouse listeners with `addEventListener`, which
8
+ * Angular's `getListeners` can't see, so each library is recognised by its
9
+ * directive class (dev builds) or by a DOM marker that's there in production
10
+ * too: a host class, or the attribute Angular renders for a static input
11
+ * (`matTooltip="Info"` → `mattooltip="Info"`).
12
+ */
13
+ import { resolveDirectives } from '../attribution.js';
14
+ const empty = (value) => value == null || String(value).trim() === '';
15
+ /** Tooltip directives we recognise. Popovers are left out: most open on click. */
16
+ const TOOLTIP_LIBRARIES = [
17
+ // Angular Material
18
+ {
19
+ directives: ['MatTooltip'],
20
+ selector: '.mat-mdc-tooltip-trigger, [mattooltip]',
21
+ textAttribute: 'mattooltip',
22
+ isOff: (d) => d['disabled'] === true || empty(d['message']),
23
+ },
24
+ // PrimeNG
25
+ {
26
+ directives: [],
27
+ genericDirectives: ['Tooltip'],
28
+ instanceKeys: ['tooltipPosition'],
29
+ selector: '[ptooltip]',
30
+ textAttribute: 'ptooltip',
31
+ isOff: (d) => d['tooltipDisabled'] === true || d['disabled'] === true,
32
+ },
33
+ // ng-bootstrap
34
+ {
35
+ directives: ['NgbTooltip'],
36
+ selector: '[ngbtooltip]',
37
+ textAttribute: 'ngbtooltip',
38
+ isOff: (d) => d['disableTooltip'] === true || empty(d['ngbTooltip']),
39
+ },
40
+ // ngx-bootstrap
41
+ {
42
+ directives: [],
43
+ genericDirectives: ['TooltipDirective'],
44
+ instanceKeys: ['tooltip'],
45
+ selector: '[tooltip]',
46
+ textAttribute: 'tooltip',
47
+ genericMarker: true,
48
+ isOff: (d) => d['isDisabled'] === true || empty(d['tooltip']),
49
+ },
50
+ // ng-zorro
51
+ {
52
+ directives: ['NzTooltipDirective'],
53
+ selector: '[nz-tooltip]',
54
+ isOff: (d) => 'nzTooltipTitle' in d && empty(d['nzTooltipTitle']),
55
+ },
56
+ // Taiga UI
57
+ { directives: ['TuiHint', 'TuiHintDirective', 'TuiHintHover'], selector: '[tuihint]', textAttribute: 'tuihint' },
58
+ // @ngneat/helipopper (Tippy.js)
59
+ {
60
+ directives: ['TippyDirective'],
61
+ selector: '[tp]',
62
+ textAttribute: 'tp',
63
+ genericMarker: true,
64
+ isOff: (d) => d['tpIsEnabled'] === false,
65
+ },
66
+ // HTML interest invokers
67
+ { directives: [], selector: '[interestfor]' },
68
+ ];
69
+ /** Every marker in one selector, so most elements cost a single `matches()`. */
70
+ const ANY_MARKER = TOOLTIP_LIBRARIES.map((lib) => lib.selector).join(', ');
71
+ const HOVER_EVENTS = ['mouseenter', 'mouseover', 'pointerenter', 'pointerover'];
72
+ /**
73
+ * Icon-font classes whose text is a ligature or glyph name, not visible text:
74
+ * Material Icons and Symbols, Font Awesome, Bootstrap Icons, PrimeIcons, Glyphicons.
75
+ */
76
+ const ICON_CLASS = /^(mat-icon|material-icons(-[\w-]+)?|material-symbols-\w+|fa-[\w-]+|fa[srlbdt]|fa-solid|fa-regular|bi-[\w-]+|pi-[\w-]+|glyphicon-[\w-]+)$/;
77
+ /**
78
+ * True when a tooltip from a known library is on `element` and switched on. A
79
+ * dev build answers from the directive instance; otherwise from the markers.
80
+ */
81
+ function hasTooltip(element) {
82
+ let marked = false;
83
+ try {
84
+ marked = element.matches(ANY_MARKER);
85
+ }
86
+ catch {
87
+ marked = false; // a selector this DOM implementation can't parse
88
+ }
89
+ // Material marks a tooltip that's switched off; this works in production too.
90
+ if (marked && element.classList.contains('mat-mdc-tooltip-disabled'))
91
+ return false;
92
+ const directives = resolveDirectives(element);
93
+ for (const lib of TOOLTIP_LIBRARIES) {
94
+ const found = directives.find((d) => lib.directives.includes(d.name) ||
95
+ (lib.genericDirectives?.includes(d.name) &&
96
+ (safeMatches(element, lib.selector) || (lib.instanceKeys ?? []).some((key) => key in d.instance))));
97
+ if (found) {
98
+ if (lib.isOff?.(found.instance) || emptyTextAttribute(element, lib))
99
+ continue;
100
+ return true;
101
+ }
102
+ if (!marked || !safeMatches(element, lib.selector))
103
+ continue;
104
+ // A marker with no directive: production, or something else using the attribute.
105
+ if (directives.length > 0 && lib.directives.length + (lib.genericDirectives?.length ?? 0) > 0)
106
+ continue;
107
+ // A registered web component may use the attribute for something else.
108
+ // Angular component hosts aren't registered custom elements, so they still count.
109
+ if (lib.genericMarker && globalThis.customElements?.get(element.localName) !== undefined)
110
+ continue;
111
+ if (emptyTextAttribute(element, lib))
112
+ continue;
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+ /** The library's text attribute is on `element` but empty: no tooltip text. */
118
+ function emptyTextAttribute(element, lib) {
119
+ return !!lib.textAttribute && element.hasAttribute(lib.textAttribute) && empty(element.getAttribute(lib.textAttribute));
120
+ }
121
+ function safeMatches(element, selector) {
122
+ try {
123
+ return element.matches(selector);
124
+ }
125
+ catch {
126
+ return false;
127
+ }
128
+ }
129
+ /**
130
+ * True when `element` shows no text of its own: no text content, an `<svg>` or
131
+ * `<img>`, or an icon-font element whose text is a ligature (`<mat-icon>info</mat-icon>`).
132
+ */
133
+ export function isIconLike(element) {
134
+ const tag = element.tagName.toLowerCase();
135
+ if (tag === 'svg' || tag === 'img' || tag === 'mat-icon')
136
+ return true;
137
+ if ([...element.classList].some((c) => ICON_CLASS.test(c)))
138
+ return true;
139
+ return (element.textContent ?? '').trim() === '';
140
+ }
141
+ /** A `title` that adds nothing to the element's `alt` or `aria-label`. */
142
+ function titleRepeatsName(element, title) {
143
+ const norm = (v) => (v ?? '').trim().toLowerCase();
144
+ return [element.getAttribute('alt'), element.getAttribute('aria-label')].some((n) => norm(n) === norm(title));
145
+ }
146
+ /**
147
+ * The strongest hover signal on `element`: a tooltip that's switched on, then an
148
+ * Angular hover listener, then a `title` on an icon. `events` are the Angular
149
+ * listener names on it (see `resolveListenerEvents`), passed in so a scan reads
150
+ * them once.
151
+ */
152
+ export function hoverSignal(element, events) {
153
+ if (hasTooltip(element))
154
+ return 'tooltip';
155
+ if (events.some((e) => HOVER_EVENTS.includes(e.split('.')[0])))
156
+ return 'hover-listener';
157
+ const title = (element.getAttribute('title') ?? '').trim();
158
+ if (title !== '' && isIconLike(element) && !titleRepeatsName(element, title))
159
+ return 'title';
160
+ return null;
161
+ }
@@ -14,12 +14,21 @@ export interface KeyboardScanOptions {
14
14
  export declare const RULE_DOCS = "https://ngbracket.com/tools/a11y-devtools/docs";
15
15
  /** A short, human CSS-ish selector for our own findings (not an axe target). */
16
16
  export declare function shortSelector(element: Element): string;
17
+ /**
18
+ * A selector that matches only `element`, for the overlay to draw the finding
19
+ * on. {@link shortSelector} can match many elements (an icon repeated in every
20
+ * table row), and the overlay would draw them all on the first. Builds an
21
+ * `:nth-child` path upward and stops as soon as it is unique, like axe's own
22
+ * targets. Undefined when the short selector is already unique, when `CSS.escape`
23
+ * is missing, or for an element in a shadow root.
24
+ */
25
+ export declare function uniqueLocator(element: Element): string | undefined;
17
26
  /** Truncated outerHTML for a finding's `html`. */
18
27
  export declare function shortHtml(element: Element): string;
19
28
  /**
20
29
  * Scan `root` for keyboard-operability problems and return them as findings.
21
- * Runs entirely in the page (needs the live `window.ng` for listeners and
22
- * attribution), so it's a no-op — empty result — in production where that global
23
- * is absent.
30
+ * Runs entirely in the page. Listener-based checks and attribution need the
31
+ * live `window.ng`, so in production only the markup-based checks (roles, tooltip
32
+ * markers, icon titles, tab order) report anything.
24
33
  */
25
34
  export declare function scanKeyboard(root?: ParentNode, options?: KeyboardScanOptions): A11yFinding[];
@@ -7,14 +7,17 @@
7
7
  * output, overlay, and report as the axe violations — attributed to the owning
8
8
  * component like everything else.
9
9
  *
10
- * Honesty guardrail: these are *heuristics*, not axe rules. `click-without-key`
11
- * and `tab-order-mismatch` are flagged as candidates to verify by hand, never as
12
- * confirmed failures.
10
+ * Honesty guardrail: these are *heuristics*, not axe rules. `click-without-key`,
11
+ * `hover-only-content`, `drag-without-keyboard` and `tab-order-mismatch` are
12
+ * flagged as candidates to verify by hand, never as confirmed failures.
13
13
  */
14
14
  import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, ngDebug, } from '../attribution.js';
15
- import { hasFocusableDescendant, hasTabbableDescendant, isHidden, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
15
+ import { hasFocusableDescendant, hasTabbableDescendant, isHidden, isDisabled, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
16
16
  import { findUncontainedModals } from './focus-trap.js';
17
+ import { hoverSignal } from './hover-content.js';
18
+ import { dragGroups, dragHandles, hasMoveControl } from './drag-drop.js';
17
19
  import { blockingModalDialog } from '../top-layer.js';
20
+ import { OVERLAY_EXCLUDE_SELECTOR } from '../overlay.js';
18
21
  /** WAI-ARIA roles that make a non-native element behave as an interactive control. */
19
22
  const INTERACTIVE_ROLES = new Set([
20
23
  'button',
@@ -43,6 +46,11 @@ const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
43
46
  function hasKeyEvent(events) {
44
47
  return events.some((e) => KEY_EVENTS.includes(e.split('.')[0]));
45
48
  }
49
+ /** True when `element` has a numeric `tabindex`, so script can focus it. */
50
+ function hasTabindex(element) {
51
+ const tabindex = element.getAttribute('tabindex');
52
+ return tabindex !== null && !Number.isNaN(Number.parseInt(tabindex, 10));
53
+ }
46
54
  /**
47
55
  * Composite widgets: Tab reaches the widget once, and arrow keys move between
48
56
  * its items (WAI-ARIA APG "Keyboard navigation inside components").
@@ -208,6 +216,17 @@ function isComponentHost(el, ng) {
208
216
  return false;
209
217
  }
210
218
  }
219
+ /**
220
+ * True when an ancestor of `element` is tabbable (focus lands there, as with an
221
+ * icon inside a link) or is in `flagged` (already reported).
222
+ */
223
+ function hasTabbableOrFlaggedAncestor(element, flagged, isVisible) {
224
+ for (let el = element.parentElement; el; el = el.parentElement) {
225
+ if (flagged.has(el) || isTabbable(el, isVisible))
226
+ return true;
227
+ }
228
+ return false;
229
+ }
211
230
  const ITEM_SELECTOR = [...INTERACTIVE_ROLES].map((role) => `[role="${role}"]`).join(',');
212
231
  /**
213
232
  * True when `element` is a click-only part of something the keyboard already
@@ -250,6 +269,47 @@ export function shortSelector(element) {
250
269
  .slice(0, 2);
251
270
  return classes.length ? `${tag}.${classes.join('.')}` : tag;
252
271
  }
272
+ /**
273
+ * A selector that matches only `element`, for the overlay to draw the finding
274
+ * on. {@link shortSelector} can match many elements (an icon repeated in every
275
+ * table row), and the overlay would draw them all on the first. Builds an
276
+ * `:nth-child` path upward and stops as soon as it is unique, like axe's own
277
+ * targets. Undefined when the short selector is already unique, when `CSS.escape`
278
+ * is missing, or for an element in a shadow root.
279
+ */
280
+ export function uniqueLocator(element) {
281
+ const doc = element.ownerDocument;
282
+ const escape = globalThis.CSS?.escape;
283
+ if (!doc || typeof escape !== 'function' || element.getRootNode() !== doc)
284
+ return undefined;
285
+ const count = (selector) => {
286
+ try {
287
+ return doc.querySelectorAll(selector).length;
288
+ }
289
+ catch {
290
+ return 0;
291
+ }
292
+ };
293
+ const short = shortSelector(element);
294
+ if (count(short) === 1 && doc.querySelector(short) === element)
295
+ return undefined;
296
+ const step = (el) => {
297
+ if (el.id && count(`#${escape(el.id)}`) === 1)
298
+ return { text: `#${escape(el.id)}`, anchored: true };
299
+ const classes = [...el.classList].slice(0, 2).map((c) => `.${escape(c)}`).join('');
300
+ const index = el.parentElement ? [...el.parentElement.children].indexOf(el) + 1 : 1;
301
+ return { text: `${el.tagName.toLowerCase()}${classes}:nth-child(${index})`, anchored: false };
302
+ };
303
+ const steps = [];
304
+ for (let el = element; el && el !== doc.documentElement; el = el.parentElement) {
305
+ const { text, anchored } = step(el);
306
+ steps.unshift(text);
307
+ const selector = steps.join(' > ');
308
+ if (anchored || count(selector) === 1)
309
+ return selector;
310
+ }
311
+ return undefined;
312
+ }
253
313
  /** Truncated outerHTML for a finding's `html`. */
254
314
  export function shortHtml(element) {
255
315
  const html = element.outerHTML ?? '';
@@ -257,9 +317,9 @@ export function shortHtml(element) {
257
317
  }
258
318
  /**
259
319
  * Scan `root` for keyboard-operability problems and return them as findings.
260
- * Runs entirely in the page (needs the live `window.ng` for listeners and
261
- * attribution), so it's a no-op — empty result — in production where that global
262
- * is absent.
320
+ * Runs entirely in the page. Listener-based checks and attribution need the
321
+ * live `window.ng`, so in production only the markup-based checks (roles, tooltip
322
+ * markers, icon titles, tab order) report anything.
263
323
  */
264
324
  export function scanKeyboard(root = document, options = {}) {
265
325
  const prefixes = options.frameworkPrefixes ?? DEFAULT_FRAMEWORK_PREFIXES;
@@ -267,6 +327,49 @@ export function scanKeyboard(root = document, options = {}) {
267
327
  const findings = [];
268
328
  const keyCache = new Map();
269
329
  const sharedCache = new Map();
330
+ /** Elements reported as unreachable controls, so the hover check doesn't repeat them. */
331
+ const unreachable = new Set();
332
+ /** Angular listener names per element, read once and shared by both passes. */
333
+ const listenerEvents = new Map();
334
+ const eventsOf = (el) => {
335
+ let events = listenerEvents.get(el);
336
+ if (!events)
337
+ listenerEvents.set(el, (events = resolveListenerEvents(el)));
338
+ return events;
339
+ };
340
+ const hoverFinding = (element, signal) => {
341
+ const url = `${RULE_DOCS}/hover-only-content`;
342
+ // The disabled control itself, or a wrapper around one (Angular Material's
343
+ // documented way to give a disabled button a tooltip): a tooltip on any
344
+ // wrapper, or other hover content on a wrapper whose only child is the control.
345
+ const only = element.children.length === 1 ? element.children[0] : null;
346
+ const disabled = isNativelyFocusable(element) && isDisabled(element)
347
+ ? element
348
+ : signal === 'tooltip'
349
+ ? [...element.querySelectorAll('button, input, select, textarea')].find(isDisabled)
350
+ : only && isNativelyFocusable(only) && isDisabled(only)
351
+ ? only
352
+ : undefined;
353
+ if (disabled) {
354
+ return make(element, 'ngbr/hover-only-content', signal === 'tooltip' ? 'moderate' : 'minor', `Keyboard users may not see this disabled control's hover content: a disabled ` +
355
+ `control can't take focus, so its tooltip only opens for the mouse. Use ` +
356
+ `aria-disabled="true" instead of disabled, or show the reason as text. ` +
357
+ `Heuristic — verify manually.`, url);
358
+ }
359
+ if (signal === 'title') {
360
+ return make(element, 'ngbr/hover-only-content', 'minor', `Only mouse users see this icon's title: Tab doesn't reach the icon, so keyboard ` +
361
+ `users can't show its title. Show the text on the page, or put the icon in a ` +
362
+ `focusable control with a visible label or tooltip. Heuristic — verify manually.`, url);
363
+ }
364
+ if (signal === 'hover-listener') {
365
+ return make(element, 'ngbr/hover-only-content', 'minor', `Keyboard users may not see what this shows on hover: it listens for the mouse ` +
366
+ `moving over it, but Tab doesn't reach it. If it shows content, make it focusable ` +
367
+ `and show the content on focus too, or show it on the page. Heuristic — verify manually.`, url);
368
+ }
369
+ return make(element, 'ngbr/hover-only-content', 'moderate', `Keyboard users may not see this tooltip: it opens on hover, but Tab doesn't reach ` +
370
+ `it. Make it focusable (a <button>, or tabindex="0") and check the tooltip opens on ` +
371
+ `focus, or show the text on the page. Heuristic — verify manually.`, url);
372
+ };
270
373
  const make = (element, id, impact, help, helpUrl) => {
271
374
  const componentPath = resolveComponentPath(element);
272
375
  return {
@@ -278,6 +381,7 @@ export function scanKeyboard(root = document, options = {}) {
278
381
  componentPath,
279
382
  directives: resolveDirectiveNames(element),
280
383
  target: shortSelector(element),
384
+ locator: uniqueLocator(element),
281
385
  html: shortHtml(element),
282
386
  };
283
387
  };
@@ -293,7 +397,7 @@ export function scanKeyboard(root = document, options = {}) {
293
397
  if (isNativelyFocusable(element))
294
398
  continue;
295
399
  const role = element.getAttribute('role')?.toLowerCase() ?? '';
296
- const events = resolveListenerEvents(element);
400
+ const events = eventsOf(element);
297
401
  const hasClick = events.includes('click');
298
402
  const interactiveByRole = INTERACTIVE_ROLES.has(role);
299
403
  if (!hasClick && !interactiveByRole)
@@ -321,9 +425,11 @@ export function scanKeyboard(root = document, options = {}) {
321
425
  `out of the tab order, like a roving-tabindex item, but nothing in or around its ` +
322
426
  `widget handles keys, so arrow keys may not move to it. Handle the arrow keys, or ` +
323
427
  `use aria-activedescendant. Heuristic — verify manually.`, `${RULE_DOCS}/unreachable-control`));
428
+ unreachable.add(element);
324
429
  continue;
325
430
  }
326
431
  const reason = interactiveByRole ? `has role="${role}"` : 'has a click handler';
432
+ unreachable.add(element);
327
433
  findings.push(make(element, 'ngbr/unreachable-control', 'serious', `Keyboard users can't reach this control: it ${reason}, but it isn't a native ` +
328
434
  `control and has no tabindex="0", so Tab skips it. Use a <button> or <a href>, ` +
329
435
  `or add tabindex="0" and Enter/Space handling.`, `${RULE_DOCS}/unreachable-control`));
@@ -338,6 +444,94 @@ export function scanKeyboard(root = document, options = {}) {
338
444
  `Use a <button>, or handle Enter and Space too. Heuristic — verify manually.`, `${RULE_DOCS}/click-without-key`));
339
445
  }
340
446
  }
447
+ // Hover-only content: a tooltip, hover listener or icon `title` on something
448
+ // 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);
451
+ for (const element of root.querySelectorAll('*')) {
452
+ if (modal && !modal.contains(element))
453
+ continue;
454
+ if (hoverFlagged.has(element) || element.closest(OVERLAY_EXCLUDE_SELECTOR))
455
+ continue;
456
+ const signal = hoverSignal(element, eventsOf(element));
457
+ if (!signal)
458
+ continue;
459
+ if (isTabbable(element, isVisible) || isHidden(element, isVisible))
460
+ continue;
461
+ // A wrapper around something Tab reaches: focus lands inside it. Skipped to
462
+ // keep false positives down, though the tooltip may still not open on focus.
463
+ if (hasTabbableDescendant(element, isVisible))
464
+ continue;
465
+ // Inside something Tab reaches (an icon in a link), or inside an element
466
+ // already reported: one finding is enough.
467
+ if (hasTabbableOrFlaggedAncestor(element, hoverFlagged, isVisible))
468
+ continue;
469
+ if (reachedWithinWidget(element, isVisible, keyCache, sharedCache) === 'reached')
470
+ continue;
471
+ hoverFlagged.add(element);
472
+ findings.push(hoverFinding(element, signal));
473
+ }
474
+ // Drag and drop with no keyboard way to move the items: no Move up / Move down
475
+ // style control near the list, and no drag handle Tab reaches that handles keys.
476
+ // One finding per list, on the list.
477
+ const groups = dragGroups(root, (el) => isHidden(el, isVisible));
478
+ const startsOf = (container, items) => [
479
+ ...new Set([container, ...items.flatMap(dragHandles)]),
480
+ ];
481
+ // A roving-tabindex board has one tab stop among all its lists; without any tab
482
+ // stop on the page's drag lists, a tabindex="-1" item is out of reach.
483
+ const anyTabStop = groups.some(({ container, items }) => startsOf(container, items).some((el) => isTabbable(el, isVisible)));
484
+ for (const { container, items, cdk } of groups) {
485
+ if (modal && !modal.contains(container))
486
+ continue;
487
+ if (container.closest(OVERLAY_EXCLUDE_SELECTOR))
488
+ continue;
489
+ if (hasMoveControl(container, (el) => isTabbable(el, isVisible)))
490
+ continue;
491
+ const starts = startsOf(container, items);
492
+ // Reachable: a tab stop, or an element script can focus (any tabindex) when a
493
+ // drag list on the page has a tab stop, as in a roving-tabindex board where
494
+ // one card is the tab stop and arrow keys move to the rest. The key-listener
495
+ // check below then decides.
496
+ const reachable = starts.filter((el) => isTabbable(el, isVisible) ||
497
+ (anyTabStop && hasTabindex(el) && !isDisabled(el) && !isHidden(el, isVisible)));
498
+ const url = `${RULE_DOCS}/drag-without-keyboard`;
499
+ const count = items.length === 1 ? '1 item here moves' : `${items.length} items here move`;
500
+ const fix = `Add buttons that move an item (Move up, Move down), or make each drag handle a ` +
501
+ `button that moves its item with the arrow keys and announces the new position. ` +
502
+ `Buttons also help people who can't drag with a mouse.`;
503
+ if (reachable.length === 0) {
504
+ findings.push(make(container, 'ngbr/drag-without-keyboard',
505
+ // Native draggable="true" is weaker evidence of a list to reorder than CDK's.
506
+ cdk ? 'serious' : 'moderate', `Keyboard users can't move these items: ${count} by drag and drop, but Tab ` +
507
+ `doesn't reach a drag handle and there's no other control to move them. ` +
508
+ `${fix} Heuristic — verify manually.`, url));
509
+ continue;
510
+ }
511
+ // The keyboard can reach a handle or item. In a production build the key
512
+ // listeners can't be seen, so assume it handles keys.
513
+ if (!listenersVisible())
514
+ continue;
515
+ // From each reachable handle up through the list, to and including the
516
+ // nearest component host above it: a sortable tab list, say, handles keys on
517
+ // a wrapper.
518
+ const ng = ngDebug();
519
+ const keyed = (start) => {
520
+ for (let el = start; el && el !== el.ownerDocument?.body; el = el.parentElement) {
521
+ if (hasKeyEvent(eventsOf(el)))
522
+ return true;
523
+ if (!container.contains(el) && isComponentHost(el, ng))
524
+ break;
525
+ }
526
+ return false;
527
+ };
528
+ const handlesKeys = reachable.some(keyed);
529
+ if (handlesKeys)
530
+ continue;
531
+ findings.push(make(container, 'ngbr/drag-without-keyboard', 'moderate', `Keyboard users may not be able to move these items: ${count} by drag and drop, ` +
532
+ `and the keyboard can reach their drag handles, but nothing on them handles keys. ` +
533
+ `${fix} Heuristic — verify manually.`, url));
534
+ }
341
535
  // Missing focus trap (M3): an open aria-modal whose focus isn't contained.
342
536
  // Reuses the tab-order machinery (inert/hidden already excluded), so a modal
343
537
  // that correctly inerts the background is not flagged.
@@ -35,8 +35,8 @@ export interface TabSequenceOptions {
35
35
  /**
36
36
  * A focus-trap sentinel: an empty, script-driven tab stop that sends focus back
37
37
  * into the modal when reached — Angular CDK / Material's `cdk-focus-trap-anchor`
38
- * (`tabindex="0"`, `aria-hidden="true"`), or a `data-focus-guard` element (the
39
- * focus-lock pattern). No text and no child elements, so it isn't real content.
38
+ * (`tabindex="0"`, `aria-hidden="true"`), PrimeNG's `p-hidden-focusable` span,
39
+ * or a `data-focus-guard` element (the focus-lock pattern). No text and no child elements, so it isn't real content.
40
40
  */
41
41
  export declare function isFocusSentinel(el: Element): boolean;
42
42
  /**
@@ -59,6 +59,8 @@ export declare function isNativelyFocusable(element: Element): boolean;
59
59
  * `tabindex="foo"`) is ignored by browsers, so it falls back to the native value.
60
60
  */
61
61
  export declare function resolvedTabIndex(element: Element): number;
62
+ /** True when `element` (or an ancestor) is disabled via a control or `<fieldset disabled>`. */
63
+ export declare function isDisabled(element: Element): boolean;
62
64
  /**
63
65
  * True when `element` isn't shown at all: structurally hidden (see
64
66
  * {@link isStructurallyHidden}) or hidden by layout. A hidden control is out of