@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.
@@ -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 {
@@ -8,13 +8,14 @@
8
8
  * component like everything else.
9
9
  *
10
10
  * Honesty guardrail: these are *heuristics*, not axe rules. `click-without-key`,
11
- * `hover-only-content` and `tab-order-mismatch` are flagged as candidates to
12
- * verify by hand, never as confirmed failures.
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
15
  import { hasFocusableDescendant, hasTabbableDescendant, isHidden, isDisabled, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
16
16
  import { findUncontainedModals } from './focus-trap.js';
17
17
  import { hoverSignal } from './hover-content.js';
18
+ import { dragGroups, dragHandles, hasMoveControl } from './drag-drop.js';
18
19
  import { blockingModalDialog } from '../top-layer.js';
19
20
  import { OVERLAY_EXCLUDE_SELECTOR } from '../overlay.js';
20
21
  /** WAI-ARIA roles that make a non-native element behave as an interactive control. */
@@ -45,6 +46,11 @@ const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
45
46
  function hasKeyEvent(events) {
46
47
  return events.some((e) => KEY_EVENTS.includes(e.split('.')[0]));
47
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
+ }
48
54
  /**
49
55
  * Composite widgets: Tab reaches the widget once, and arrow keys move between
50
56
  * its items (WAI-ARIA APG "Keyboard navigation inside components").
@@ -465,6 +471,67 @@ export function scanKeyboard(root = document, options = {}) {
465
471
  hoverFlagged.add(element);
466
472
  findings.push(hoverFinding(element, signal));
467
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
+ }
468
535
  // Missing focus trap (M3): an open aria-modal whose focus isn't contained.
469
536
  // Reuses the tab-order machinery (inert/hidden already excluded), so a modal
470
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
  /**
@@ -16,8 +16,8 @@ import { blockingModalDialog } from '../top-layer.js';
16
16
  /**
17
17
  * A focus-trap sentinel: an empty, script-driven tab stop that sends focus back
18
18
  * into the modal when reached — Angular CDK / Material's `cdk-focus-trap-anchor`
19
- * (`tabindex="0"`, `aria-hidden="true"`), or a `data-focus-guard` element (the
20
- * focus-lock pattern). No text and no child elements, so it isn't real content.
19
+ * (`tabindex="0"`, `aria-hidden="true"`), PrimeNG's `p-hidden-focusable` span,
20
+ * or a `data-focus-guard` element (the focus-lock pattern). No text and no child elements, so it isn't real content.
21
21
  */
22
22
  export function isFocusSentinel(el) {
23
23
  if (el.childElementCount > 0 || (el.textContent ?? '').trim() !== '')
@@ -25,14 +25,41 @@ export function isFocusSentinel(el) {
25
25
  return el.getAttribute('aria-hidden') === 'true' || el.hasAttribute('data-focus-guard');
26
26
  }
27
27
  /**
28
- * The open `aria-modal` whose focus a JS trap keeps in, or null: its stops are
29
- * one unbroken run in `order` with a sentinel directly before and after. The
30
- * browser can reach those sentinels, but the trap sends focus from them back
31
- * into the modal. Checked with real Tab presses on a CDK dialog: from the last
28
+ * Dialogs from libraries that trap Tab with a script and add no sentinels:
29
+ * ng-bootstrap's modal and offcanvas (`ngbFocusTrap`). They're recognised by
30
+ * element name, which is there in production builds too.
31
+ */
32
+ const SCRIPT_TRAP_SELECTOR = 'ngb-modal-window, ngb-offcanvas-panel';
33
+ /**
34
+ * Elements that may hold a JS focus trap: any `aria-modal`, any dialog role, the
35
+ * Angular CDK / Material dialog containers, and {@link SCRIPT_TRAP_SELECTOR}.
36
+ * Material 22 opens `mat-dialog` with `aria-modal="false"` (it hides the page
37
+ * with `aria-hidden` instead), so `aria-modal="true"` alone misses every default
38
+ * Material dialog.
39
+ */
40
+ const TRAP_CANDIDATE_SELECTOR = [
41
+ '[aria-modal="true"]',
42
+ '[role="dialog"]',
43
+ '[role="alertdialog"]',
44
+ 'mat-dialog-container',
45
+ '.cdk-dialog-container',
46
+ SCRIPT_TRAP_SELECTOR,
47
+ ].join(', ');
48
+ /**
49
+ * The open dialog whose focus a JS trap keeps in, or null. Its stops must be one
50
+ * unbroken run in `order`, and one of these holds:
51
+ * - a sentinel sits directly before and after the run, outside the dialog
52
+ * (Angular CDK / Material: the anchors are the dialog container's siblings);
53
+ * - the run starts and ends with a sentinel inside the dialog (PrimeNG's
54
+ * `pFocusTrap` prepends and appends hidden spans; ngx-bootstrap's
55
+ * `modal-container` holds its CDK-style anchors around `.modal-dialog`);
56
+ * - the dialog is one of {@link SCRIPT_TRAP_SELECTOR}.
57
+ * The browser can reach those sentinels, but the trap sends focus from them back
58
+ * into the dialog. Checked with real Tab presses on a CDK dialog: from the last
32
59
  * control, Tab wraps to the first. With several, the last is the topmost.
33
60
  */
34
61
  function sentinelTrappedModal(root, order) {
35
- const modals = [...root.querySelectorAll('[aria-modal="true"]')].reverse();
62
+ const modals = [...root.querySelectorAll(TRAP_CANDIDATE_SELECTOR)].reverse();
36
63
  for (const modal of modals) {
37
64
  const inside = order.map((el) => modal.contains(el));
38
65
  const first = inside.indexOf(true);
@@ -43,6 +70,10 @@ function sentinelTrappedModal(root, order) {
43
70
  const after = order[last + 1];
44
71
  if (before && after && isFocusSentinel(before) && isFocusSentinel(after))
45
72
  return modal;
73
+ if (last > first && isFocusSentinel(order[first]) && isFocusSentinel(order[last]))
74
+ return modal;
75
+ if (modal.matches(SCRIPT_TRAP_SELECTOR))
76
+ return modal;
46
77
  }
47
78
  return null;
48
79
  }
@@ -0,0 +1,29 @@
1
+ import { type TabSequenceOptions } from './tab-sequence.js';
2
+ /** One tab stop in the walkthrough. Plain data, so it survives JSON. */
3
+ export interface WalkthroughStep {
4
+ /** 1-based position in the tab order. */
5
+ order: number;
6
+ /** Computed ARIA role, or null when none resolves. */
7
+ role: string | null;
8
+ /** Computed accessible name; '' when it has none. */
9
+ name: string;
10
+ /** Computed accessible description, or ''. */
11
+ description: string;
12
+ /** State labels, e.g. `['expanded', 'required']`. */
13
+ states: string[];
14
+ /** Tag name of the element, e.g. `button`. */
15
+ tag: string;
16
+ /** True when a positive `tabindex` puts this stop out of DOM order. */
17
+ positive: boolean;
18
+ /** Owning app component, or null. */
19
+ component: string | null;
20
+ }
21
+ /** Steps past this many are dropped; the report says how many there were. */
22
+ export declare const WALKTHROUGH_MAX_STEPS = 300;
23
+ export interface Walkthrough {
24
+ steps: WalkthroughStep[];
25
+ /** Tab stops on the page. More than `steps.length` when the list was capped. */
26
+ total: number;
27
+ }
28
+ /** Walk the tab order of `root` and describe each stop. */
29
+ export declare function linearWalkthrough(root?: ParentNode, options?: Pick<TabSequenceOptions, 'frameworkPrefixes'>): Promise<Walkthrough>;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The linear walkthrough: the page's tab order as a reading list, each stop with
3
+ * its computed role, name and states and the component that rendered it. It's
4
+ * the report-mode form of the overlay's tab-order path and Focus preview.
5
+ *
6
+ * Like the Focus preview, this is a *computed approximation* (see `accname.ts`),
7
+ * never what any one screen reader says.
8
+ */
9
+ import { describeElements } from './accname.js';
10
+ import { tabSequence } from './tab-sequence.js';
11
+ /** Steps past this many are dropped; the report says how many there were. */
12
+ export const WALKTHROUGH_MAX_STEPS = 300;
13
+ /** Walk the tab order of `root` and describe each stop. */
14
+ export async function linearWalkthrough(root = document, options = {}) {
15
+ const stops = tabSequence(root, options);
16
+ const kept = stops.slice(0, WALKTHROUGH_MAX_STEPS);
17
+ const described = await describeElements(kept.map((s) => s.element));
18
+ const steps = kept.map((stop, i) => ({
19
+ order: stop.order,
20
+ role: described[i].role,
21
+ name: described[i].name.replace(/\s+/g, ' ').trim(),
22
+ description: described[i].description,
23
+ states: described[i].states,
24
+ tag: stop.element.tagName.toLowerCase(),
25
+ positive: stop.positive,
26
+ component: stop.component,
27
+ }));
28
+ return { steps, total: stops.length };
29
+ }
package/dist/overlay.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { A11yFinding } from './scan.js';
1
+ import type { A11yFinding, Impact } from './scan.js';
2
2
  import type { TabStop } from './keyboard/tab-sequence.js';
3
3
  import type { AxDescription } from './keyboard/accname.js';
4
4
  /**
@@ -8,6 +8,11 @@ import type { AxDescription } from './keyboard/accname.js';
8
8
  export declare const OVERLAY_ATTR = "data-ngb-a11y-overlay";
9
9
  /** Selector form of {@link OVERLAY_ATTR}, passed to axe as an exclude. */
10
10
  export declare const OVERLAY_EXCLUDE_SELECTOR = "[data-ngb-a11y-overlay]";
11
+ /**
12
+ * Label fill per impact, behind white 11px text: at least 4.5:1 with white, in
13
+ * the same hue as the border, so the labels pass a contrast check themselves.
14
+ */
15
+ export declare const IMPACT_LABEL_FILL: Record<NonNullable<Impact> | 'none', string>;
11
16
  /** The computed accessibility-tree info shown in the focus-follow panel. */
12
17
  export interface AxPanelData extends AxDescription {
13
18
  /** Owning component of the focused element, or null. */
package/dist/overlay.js CHANGED
@@ -32,7 +32,7 @@ const IMPACT_COLOR = {
32
32
  * Label fill per impact, behind white 11px text: at least 4.5:1 with white, in
33
33
  * the same hue as the border, so the labels pass a contrast check themselves.
34
34
  */
35
- const IMPACT_LABEL_FILL = {
35
+ export const IMPACT_LABEL_FILL = {
36
36
  critical: '#d32029',
37
37
  serious: '#b45309',
38
38
  moderate: '#8a6d00',
@@ -5,6 +5,8 @@ export interface PillMenuOptions {
5
5
  onChange: (settings: DevtoolsSettings) => void;
6
6
  /** Download the report for the pages visited so far. */
7
7
  onDownload: () => void;
8
+ /** Show only one component's issues (`null`: every component). */
9
+ onComponentChange?: (component: string | null) => void;
8
10
  /** Open the panel above the button (pill at the bottom) or below it. */
9
11
  opensUp: boolean;
10
12
  /** Align the panel's left edge (pill on the left) or right edge. */
@@ -17,6 +19,13 @@ export interface PillMenuStatus {
17
19
  shown: number;
18
20
  /** Pages recorded for the report. */
19
21
  pages: number;
22
+ /** Components with issues on this page, most issues first. */
23
+ components?: {
24
+ name: string;
25
+ count: number;
26
+ }[];
27
+ /** The component filter in force, or null for every component. */
28
+ component?: string | null;
20
29
  }
21
30
  export interface PillMenu {
22
31
  /** The `⋯` button that opens the panel. */
package/dist/pill-menu.js CHANGED
@@ -102,7 +102,7 @@ export function createPillMenu(doc, options) {
102
102
  select.append(opt);
103
103
  }
104
104
  select.value = settings.minImpact;
105
- Object.assign(select.style, {
105
+ const selectStyle = {
106
106
  width: '100%',
107
107
  minHeight: '28px',
108
108
  marginBottom: '10px',
@@ -111,8 +111,42 @@ export function createPillMenu(doc, options) {
111
111
  background: '#2a2e37',
112
112
  border: '1px solid rgba(255,255,255,0.3)',
113
113
  borderRadius: '4px',
114
- });
114
+ };
115
+ Object.assign(select.style, selectStyle);
115
116
  select.addEventListener('change', () => update({ minImpact: select.value }));
117
+ // Per-component filter. Its options follow the components on the current page.
118
+ const componentLabel = doc.createElement('label');
119
+ componentLabel.textContent = 'Show component';
120
+ Object.assign(componentLabel.style, { display: 'block', fontWeight: '700', marginBottom: '4px' });
121
+ const componentSelect = doc.createElement('select');
122
+ componentSelect.id = `${id}-component`;
123
+ componentLabel.htmlFor = componentSelect.id;
124
+ Object.assign(componentSelect.style, selectStyle);
125
+ componentSelect.addEventListener('change', () => options.onComponentChange?.(componentSelect.value || null));
126
+ let componentOptionsKey = '';
127
+ /** Rebuild the options only when they change, so an open select isn't reset under the user. */
128
+ function setComponentOptions(components, selected) {
129
+ const list = [...components];
130
+ // Keep a chosen component listed after its issues are fixed, so the filter stays visible.
131
+ if (selected && !list.some((c) => c.name === selected))
132
+ list.push({ name: selected, count: 0 });
133
+ const key = JSON.stringify([list, selected]);
134
+ if (key === componentOptionsKey)
135
+ return;
136
+ componentOptionsKey = key;
137
+ const all = doc.createElement('option');
138
+ all.value = '';
139
+ all.textContent = 'All components';
140
+ const opts = list.map(({ name, count }) => {
141
+ const opt = doc.createElement('option');
142
+ opt.value = name;
143
+ opt.textContent = `${name} (${count})`;
144
+ return opt;
145
+ });
146
+ componentSelect.replaceChildren(all, ...opts);
147
+ componentSelect.value = selected ?? '';
148
+ }
149
+ setComponentOptions([], null);
116
150
  const download = doc.createElement('button');
117
151
  download.type = 'button';
118
152
  download.textContent = 'Download report';
@@ -129,7 +163,8 @@ export function createPillMenu(doc, options) {
129
163
  download.addEventListener('click', () => options.onDownload());
130
164
  const pagesNote = doc.createElement('p');
131
165
  Object.assign(pagesNote.style, { margin: '4px 0 0', fontSize: '12px', color: muted });
132
- panel.append(status, fieldset, severityLabel, select, download, pagesNote);
166
+ const componentControls = options.onComponentChange ? [componentLabel, componentSelect] : [];
167
+ panel.append(status, fieldset, severityLabel, select, ...componentControls, download, pagesNote);
133
168
  function update(patch) {
134
169
  settings = { ...settings, ...patch };
135
170
  options.onChange(settings);
@@ -157,7 +192,7 @@ export function createPillMenu(doc, options) {
157
192
  };
158
193
  doc.addEventListener('pointerdown', onPointerDown, true);
159
194
  // Inline styles can't do :focus-visible; draw the rings from focus events.
160
- for (const el of [button, download, select]) {
195
+ for (const el of [button, download, select, componentSelect]) {
161
196
  el.addEventListener('focus', () => {
162
197
  if (el.matches(':focus-visible')) {
163
198
  el.style.outline = '2px solid #7ab8ff';
@@ -171,7 +206,9 @@ export function createPillMenu(doc, options) {
171
206
  return {
172
207
  button,
173
208
  panel,
174
- setStatus({ found, shown, pages }) {
209
+ setStatus({ found, shown, pages, components, component }) {
210
+ if (components)
211
+ setComponentOptions(components, component ?? null);
175
212
  const issues = `${found} ${found === 1 ? 'issue' : 'issues'} on this page`;
176
213
  status.textContent = shown === found ? issues : `${issues}, ${shown} shown`;
177
214
  pagesNote.textContent = `Covers ${pages} ${pages === 1 ? 'page' : 'pages'} visited since the app loaded.`;
@@ -31,7 +31,8 @@ export interface A11yDevtoolsOptions {
31
31
  /**
32
32
  * Turn on the **keyboard layer** — the ~2/3 of accessibility axe can't test.
33
33
  * Adds heuristic `ngbr/*` findings (keyboard-unreachable controls,
34
- * click-without-keyboard handlers, hover-only content, tab-order mismatches)
34
+ * click-without-keyboard handlers, hover-only content, drag and drop with no
35
+ * keyboard way, tab-order mismatches)
35
36
  * to the report, and,
36
37
  * when `overlay` is on, draws the numbered tab-order path over the page.
37
38
  * Default false.
package/dist/provider.js CHANGED
@@ -6,7 +6,7 @@ import { tabSequence } from './keyboard/tab-sequence.js';
6
6
  import { describeElement } from './keyboard/accname.js';
7
7
  import { resolveOwningComponentName } from './attribution.js';
8
8
  import { createTogglePill, DEFAULT_TOGGLE_SHORTCUT, matchesShortcut, parseShortcut, readStoredEnabled, writeStoredEnabled, } from './toggle.js';
9
- import { readStoredSettings, resolveSettings, visibleFindings, writeStoredSettings, } from './settings.js';
9
+ import { componentCounts, readStoredSettings, resolveSettings, visibleFindings, worstImpact, writeStoredSettings, } from './settings.js';
10
10
  /**
11
11
  * Dev-only in-app accessibility auditing. Rescans whenever the application
12
12
  * settles (zoneless-aware, via `ApplicationRef.isStable`) and reports each
@@ -57,10 +57,24 @@ function devtoolsProviders(options) {
57
57
  // and the latest findings per route visited, for the downloadable report.
58
58
  let lastFindings = [];
59
59
  const visited = new Map();
60
+ // Show one component's issues only (null: all). Not remembered, and reset
61
+ // on a route change: the components change from page to page.
62
+ let componentFilter = null;
63
+ let lastPath;
60
64
  /** Draw (or clear) each overlay layer from the last scan and the settings. */
61
65
  function draw() {
62
- const shown = settings.highlights ? visibleFindings(lastFindings, settings.minImpact) : [];
63
- pillView?.setStatus({ found: lastFindings.length, shown: shown.length, pages: visited.size });
66
+ const matching = visibleFindings(lastFindings, settings.minImpact, componentFilter);
67
+ const shown = settings.highlights ? matching : [];
68
+ pillView?.setStatus({
69
+ found: lastFindings.length,
70
+ shown: shown.length,
71
+ pages: visited.size,
72
+ matching: matching.length,
73
+ worst: worstImpact(matching),
74
+ // Counted at the chosen severity, so an option's count matches the badge.
75
+ components: componentCounts(visibleFindings(lastFindings, settings.minImpact)),
76
+ component: componentFilter,
77
+ });
64
78
  if (!overlayView)
65
79
  return;
66
80
  if (!enabled) {
@@ -137,7 +151,17 @@ function devtoolsProviders(options) {
137
151
  onToggle: setEnabled,
138
152
  shortcut,
139
153
  position: pill,
140
- menu: overlayView ? { settings, onChange: setSettings, onDownload: downloadReport } : undefined,
154
+ menu: overlayView
155
+ ? {
156
+ settings,
157
+ onChange: setSettings,
158
+ onDownload: downloadReport,
159
+ onComponentChange: (component) => {
160
+ componentFilter = component;
161
+ draw();
162
+ },
163
+ }
164
+ : undefined,
141
165
  })
142
166
  : undefined;
143
167
  let onKeyDown;
@@ -217,6 +241,10 @@ function devtoolsProviders(options) {
217
241
  return; // switched off mid-scan: draw nothing
218
242
  lastFindings = findings;
219
243
  const route = location.pathname + location.search;
244
+ // A new path is a new page; a query-string change (?page=2) keeps the filter.
245
+ if (lastPath !== undefined && location.pathname !== lastPath)
246
+ componentFilter = null;
247
+ lastPath = location.pathname;
220
248
  // Label by route: a single-page app usually keeps one title on every route.
221
249
  visited.set(route, { label: route, url: location.href, findings });
222
250
  draw();
@@ -18,6 +18,7 @@ const NGBR_RULES = {
18
18
  'ngbr/unreachable-control': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
19
19
  'ngbr/click-without-key': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
20
20
  'ngbr/hover-only-content': { criteria: ['2.1.1'], ranWhen: 'keyboard' },
21
+ 'ngbr/drag-without-keyboard': { criteria: ['2.1.1', '2.5.7'], ranWhen: 'keyboard' },
21
22
  'ngbr/tab-order-mismatch': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
22
23
  'ngbr/modal-focus-not-contained': { criteria: ['2.4.3'], ranWhen: 'keyboard' },
23
24
  'ngbr/focus-trap': { criteria: ['2.1.2'], ranWhen: 'focusTraps' },
@@ -1,5 +1,6 @@
1
1
  import type { A11yFinding, Impact } from '../scan.js';
2
2
  import type { BaselineDiff } from './baseline.js';
3
+ import type { Walkthrough, WalkthroughStep } from '../keyboard/walkthrough.js';
3
4
  /**
4
5
  * Pure formatting for report-mode: grouping + Markdown/JSON serialization. Kept
5
6
  * free of any Node or Playwright imports so the browser side (`report.ts`) can
@@ -21,9 +22,20 @@ export interface PageReport {
21
22
  * ones that don't also appear in the light pass of the same route.
22
23
  */
23
24
  darkOnly?: boolean;
25
+ /** The tab order with each stop's computed role and name, when the run asked for it. */
26
+ walkthrough?: Walkthrough;
24
27
  }
25
28
  /** One-line explanation for a dark-only page, shared by the Markdown and HTML reports. */
26
29
  export declare const DARK_ONLY_NOTE = "Dark mode: lists only issues that don\u2019t also appear in light mode on this route.";
30
+ /**
31
+ * Heading note for the walkthrough, shared by the Markdown and HTML reports. Same
32
+ * honesty rule as the overlay's Focus preview: computed, not a screen reader.
33
+ */
34
+ export declare const WALKTHROUGH_NOTE: string;
35
+ /** One walkthrough step as a single line, e.g. `button "Save" (disabled) — SaveBarComponent`. */
36
+ export declare function formatStep(step: WalkthroughStep): string;
37
+ /** "Showing the first 300 of 412 tab stops." when the list was capped, else ''. */
38
+ export declare function walkthroughCapNote(walkthrough: Walkthrough): string;
27
39
  /**
28
40
  * Report title, shared by every format. Says "automated scan" on purpose: a file
29
41
  * titled "Accessibility report" is easy to hand to procurement as if it were a
@@ -48,6 +60,8 @@ export interface ScanChecks {
48
60
  keyboard: boolean;
49
61
  /** The real-Tab keyboard-trap walk (`ngbr/focus-trap`) ran. */
50
62
  focusTraps: boolean;
63
+ /** Each page lists its tab order with computed roles and names. */
64
+ walkthrough?: boolean;
51
65
  }
52
66
  /** A whole report-mode run across one or more pages. */
53
67
  export interface ScanReport {