@ngbracket/a11y-devtools 0.16.0 → 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.
- package/CHANGELOG.md +40 -0
- package/dist/inpage.global.js +109 -2
- package/dist/keyboard/drag-drop.d.ts +45 -0
- package/dist/keyboard/drag-drop.js +95 -0
- package/dist/keyboard/focus-walk.js +4 -1
- package/dist/keyboard/keyboard-scan.js +69 -2
- package/dist/keyboard/tab-sequence.d.ts +2 -2
- package/dist/keyboard/tab-sequence.js +38 -7
- package/dist/provider.d.ts +2 -1
- package/dist/report/acr.js +1 -0
- package/dist/report/headless.d.ts +2 -1
- package/dist/runner.d.ts +2 -1
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,46 @@
|
|
|
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.17.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- New keyboard rule `ngbr/drag-without-keyboard`. It reports a list whose items
|
|
11
|
+
move by drag and drop when the tool finds no keyboard way to move them.
|
|
12
|
+
Angular CDK drag and drop has no keyboard support of its own, so a list of
|
|
13
|
+
rows with `cdkDragHandle` icons is mouse-only unless the app adds one. The
|
|
14
|
+
rule finds drag items by the `cdk-drag` class inside a `cdk-drop-list`, and
|
|
15
|
+
by `draggable="true"` when a parent holds two or more, in any build. It
|
|
16
|
+
reports each list once. It skips a list with a tab stop in or next to it
|
|
17
|
+
whose name says it moves an item ("Move up", "Reorder", an arrow, a Material
|
|
18
|
+
`arrow_upward` icon). Serious when the keyboard can't reach a drag handle of a
|
|
19
|
+
CDK list; moderate for a native `draggable` list. A handle or item with a
|
|
20
|
+
`tabindex` counts as reachable when a drag list on the page has a tab stop,
|
|
21
|
+
as in a board where one card is the tab stop and the arrow keys move to the
|
|
22
|
+
rest. Moderate in a dev build when a handle is reachable but no Angular key
|
|
23
|
+
listener sits on the handle, its item, the list, or the elements up to and
|
|
24
|
+
including the component that holds the list. Maps to WCAG 2.1.1 and
|
|
25
|
+
2.5.7 in the ACR worksheet.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- The tab-order layer now hides the page's tab stops while an Angular Material
|
|
30
|
+
dialog is open. Material 22 opens `mat-dialog` with `aria-modal="false"` by
|
|
31
|
+
default and hides the page from screen readers with `aria-hidden`. The
|
|
32
|
+
scanner only looked for the CDK focus trap around `aria-modal="true"`
|
|
33
|
+
elements, so it missed the trap and numbered the page's stops under the
|
|
34
|
+
dialog as well as the dialog's own. It now finds the trap around any
|
|
35
|
+
`mat-dialog-container`, `.cdk-dialog-container` or dialog role. Report mode
|
|
36
|
+
also no longer counts Tab cycling inside a default `mat-dialog` as a
|
|
37
|
+
`ngbr/focus-trap` finding.
|
|
38
|
+
- The scanner now recognises the focus traps in PrimeNG, ngx-bootstrap and
|
|
39
|
+
ng-bootstrap dialogs. PrimeNG and ngx-bootstrap put their sentinels inside
|
|
40
|
+
the dialog, as its first and last tab stops. ng-bootstrap's modal and
|
|
41
|
+
offcanvas trap Tab with a script and no sentinels, so they're recognised by
|
|
42
|
+
element name. Before, the tab-order layer showed the page's stops under these
|
|
43
|
+
dialogs, and `ngbr/modal-focus-not-contained` reported a leak that wasn't
|
|
44
|
+
there.
|
|
45
|
+
|
|
6
46
|
## 0.16.0
|
|
7
47
|
|
|
8
48
|
### Added
|
package/dist/inpage.global.js
CHANGED
|
@@ -34630,8 +34630,17 @@
|
|
|
34630
34630
|
return false;
|
|
34631
34631
|
return el.getAttribute("aria-hidden") === "true" || el.hasAttribute("data-focus-guard");
|
|
34632
34632
|
}
|
|
34633
|
+
var SCRIPT_TRAP_SELECTOR = "ngb-modal-window, ngb-offcanvas-panel";
|
|
34634
|
+
var TRAP_CANDIDATE_SELECTOR = [
|
|
34635
|
+
'[aria-modal="true"]',
|
|
34636
|
+
'[role="dialog"]',
|
|
34637
|
+
'[role="alertdialog"]',
|
|
34638
|
+
"mat-dialog-container",
|
|
34639
|
+
".cdk-dialog-container",
|
|
34640
|
+
SCRIPT_TRAP_SELECTOR
|
|
34641
|
+
].join(", ");
|
|
34633
34642
|
function sentinelTrappedModal(root, order) {
|
|
34634
|
-
const modals = [...root.querySelectorAll(
|
|
34643
|
+
const modals = [...root.querySelectorAll(TRAP_CANDIDATE_SELECTOR)].reverse();
|
|
34635
34644
|
for (const modal of modals) {
|
|
34636
34645
|
const inside = order.map((el) => modal.contains(el));
|
|
34637
34646
|
const first = inside.indexOf(true);
|
|
@@ -34642,6 +34651,10 @@
|
|
|
34642
34651
|
const after = order[last + 1];
|
|
34643
34652
|
if (before && after && isFocusSentinel(before) && isFocusSentinel(after))
|
|
34644
34653
|
return modal;
|
|
34654
|
+
if (last > first && isFocusSentinel(order[first]) && isFocusSentinel(order[last]))
|
|
34655
|
+
return modal;
|
|
34656
|
+
if (modal.matches(SCRIPT_TRAP_SELECTOR))
|
|
34657
|
+
return modal;
|
|
34645
34658
|
}
|
|
34646
34659
|
return null;
|
|
34647
34660
|
}
|
|
@@ -34945,6 +34958,51 @@
|
|
|
34945
34958
|
return null;
|
|
34946
34959
|
}
|
|
34947
34960
|
|
|
34961
|
+
// dist/keyboard/drag-drop.js
|
|
34962
|
+
var DRAG_ITEM_SELECTOR = '.cdk-drop-list .cdk-drag, [draggable="true"]';
|
|
34963
|
+
var DRAG_LIST_SELECTOR = '.cdk-drop-list, [draggable="true"]';
|
|
34964
|
+
var 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;
|
|
34965
|
+
var CONTROL_SELECTOR = 'button, a[href], [role="button"], [role="menuitem"]';
|
|
34966
|
+
function dragGroups(root, isHidden2) {
|
|
34967
|
+
const groups = /* @__PURE__ */ new Map();
|
|
34968
|
+
for (const item of root.querySelectorAll(DRAG_ITEM_SELECTOR)) {
|
|
34969
|
+
if (item.matches(".cdk-drag-disabled, .cdk-drag-preview, .cdk-drag-placeholder"))
|
|
34970
|
+
continue;
|
|
34971
|
+
if (!item.classList.contains("cdk-drag") && item.parentElement?.closest(".cdk-drag"))
|
|
34972
|
+
continue;
|
|
34973
|
+
const container = item.classList.contains("cdk-drag") ? item.parentElement?.closest(".cdk-drop-list") : item.parentElement;
|
|
34974
|
+
if (!container || container.classList.contains("cdk-drop-list-disabled"))
|
|
34975
|
+
continue;
|
|
34976
|
+
if (isHidden2(item))
|
|
34977
|
+
continue;
|
|
34978
|
+
const items = groups.get(container) ?? [];
|
|
34979
|
+
items.push(item);
|
|
34980
|
+
groups.set(container, items);
|
|
34981
|
+
}
|
|
34982
|
+
return [...groups].map(([container, items]) => ({ container, items, cdk: items[0].classList.contains("cdk-drag") })).filter((group) => group.cdk || group.items.length >= 2);
|
|
34983
|
+
}
|
|
34984
|
+
function dragHandles(item) {
|
|
34985
|
+
const handles = [...item.querySelectorAll(".cdk-drag-handle")].filter((handle) => handle.closest('.cdk-drag, [draggable="true"]') === item);
|
|
34986
|
+
return handles.length > 0 ? handles : [item];
|
|
34987
|
+
}
|
|
34988
|
+
function roughName(element) {
|
|
34989
|
+
const labelledBy = (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).map((id) => id ? element.ownerDocument?.getElementById(id)?.textContent ?? "" : "").join(" ");
|
|
34990
|
+
return [element.getAttribute("aria-label"), labelledBy, element.getAttribute("title"), element.textContent].filter(Boolean).join(" ");
|
|
34991
|
+
}
|
|
34992
|
+
function hasMoveControl(container, isTabbable2) {
|
|
34993
|
+
const siblings = [...container.parentElement?.children ?? []].filter((el) => el !== container && !el.matches(DRAG_LIST_SELECTOR) && !el.querySelector(DRAG_LIST_SELECTOR));
|
|
34994
|
+
for (const scope of [container, ...siblings]) {
|
|
34995
|
+
const controls = [...scope.matches(CONTROL_SELECTOR) ? [scope] : [], ...scope.querySelectorAll(CONTROL_SELECTOR)];
|
|
34996
|
+
for (const control of controls) {
|
|
34997
|
+
if (control.closest(".cdk-drag-handle"))
|
|
34998
|
+
continue;
|
|
34999
|
+
if (MOVE_NAME.test(roughName(control)) && isTabbable2(control))
|
|
35000
|
+
return true;
|
|
35001
|
+
}
|
|
35002
|
+
}
|
|
35003
|
+
return false;
|
|
35004
|
+
}
|
|
35005
|
+
|
|
34948
35006
|
// dist/keyboard/keyboard-scan.js
|
|
34949
35007
|
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
34950
35008
|
"button",
|
|
@@ -34968,6 +35026,10 @@
|
|
|
34968
35026
|
function hasKeyEvent(events) {
|
|
34969
35027
|
return events.some((e) => KEY_EVENTS.includes(e.split(".")[0]));
|
|
34970
35028
|
}
|
|
35029
|
+
function hasTabindex(element) {
|
|
35030
|
+
const tabindex = element.getAttribute("tabindex");
|
|
35031
|
+
return tabindex !== null && !Number.isNaN(Number.parseInt(tabindex, 10));
|
|
35032
|
+
}
|
|
34971
35033
|
var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
|
|
34972
35034
|
function reachedWithinWidget(element, isVisible, keyCache = /* @__PURE__ */ new Map(), sharedCache = /* @__PURE__ */ new Map()) {
|
|
34973
35035
|
const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
|
|
@@ -35236,6 +35298,51 @@
|
|
|
35236
35298
|
hoverFlagged.add(element);
|
|
35237
35299
|
findings.push(hoverFinding(element, signal));
|
|
35238
35300
|
}
|
|
35301
|
+
const groups = dragGroups(root, (el) => isHidden(el, isVisible));
|
|
35302
|
+
const startsOf = (container, items) => [
|
|
35303
|
+
.../* @__PURE__ */ new Set([container, ...items.flatMap(dragHandles)])
|
|
35304
|
+
];
|
|
35305
|
+
const anyTabStop = groups.some(({ container, items }) => startsOf(container, items).some((el) => isTabbable(el, isVisible)));
|
|
35306
|
+
for (const { container, items, cdk } of groups) {
|
|
35307
|
+
if (modal && !modal.contains(container))
|
|
35308
|
+
continue;
|
|
35309
|
+
if (container.closest(OVERLAY_EXCLUDE_SELECTOR))
|
|
35310
|
+
continue;
|
|
35311
|
+
if (hasMoveControl(container, (el) => isTabbable(el, isVisible)))
|
|
35312
|
+
continue;
|
|
35313
|
+
const starts = startsOf(container, items);
|
|
35314
|
+
const reachable = starts.filter((el) => isTabbable(el, isVisible) || anyTabStop && hasTabindex(el) && !isDisabled(el) && !isHidden(el, isVisible));
|
|
35315
|
+
const url = `${RULE_DOCS}/drag-without-keyboard`;
|
|
35316
|
+
const count = items.length === 1 ? "1 item here moves" : `${items.length} items here move`;
|
|
35317
|
+
const fix = `Add buttons that move an item (Move up, Move down), or make each drag handle a button that moves its item with the arrow keys and announces the new position. Buttons also help people who can't drag with a mouse.`;
|
|
35318
|
+
if (reachable.length === 0) {
|
|
35319
|
+
findings.push(make(
|
|
35320
|
+
container,
|
|
35321
|
+
"ngbr/drag-without-keyboard",
|
|
35322
|
+
// Native draggable="true" is weaker evidence of a list to reorder than CDK's.
|
|
35323
|
+
cdk ? "serious" : "moderate",
|
|
35324
|
+
`Keyboard users can't move these items: ${count} by drag and drop, but Tab doesn't reach a drag handle and there's no other control to move them. ${fix} Heuristic \u2014 verify manually.`,
|
|
35325
|
+
url
|
|
35326
|
+
));
|
|
35327
|
+
continue;
|
|
35328
|
+
}
|
|
35329
|
+
if (!listenersVisible())
|
|
35330
|
+
continue;
|
|
35331
|
+
const ng = ngDebug();
|
|
35332
|
+
const keyed = (start) => {
|
|
35333
|
+
for (let el = start; el && el !== el.ownerDocument?.body; el = el.parentElement) {
|
|
35334
|
+
if (hasKeyEvent(eventsOf(el)))
|
|
35335
|
+
return true;
|
|
35336
|
+
if (!container.contains(el) && isComponentHost(el, ng))
|
|
35337
|
+
break;
|
|
35338
|
+
}
|
|
35339
|
+
return false;
|
|
35340
|
+
};
|
|
35341
|
+
const handlesKeys2 = reachable.some(keyed);
|
|
35342
|
+
if (handlesKeys2)
|
|
35343
|
+
continue;
|
|
35344
|
+
findings.push(make(container, "ngbr/drag-without-keyboard", "moderate", `Keyboard users may not be able to move these items: ${count} by drag and drop, and the keyboard can reach their drag handles, but nothing on them handles keys. ${fix} Heuristic \u2014 verify manually.`, url));
|
|
35345
|
+
}
|
|
35239
35346
|
for (const modal2 of findUncontainedModals(root, { frameworkPrefixes: prefixes, isVisible })) {
|
|
35240
35347
|
findings.push(make(modal2.element, "ngbr/modal-focus-not-contained", "moderate", `Keyboard users can Tab out of this modal: it has aria-modal="true", but ${modal2.outsideCount} control(s) outside it can still be reached with Tab. Open it with <dialog>.showModal(), make the rest of the page inert, or trap focus. Heuristic \u2014 verify manually.`, `${RULE_DOCS}/modal-focus-not-contained`));
|
|
35241
35348
|
}
|
|
@@ -35281,7 +35388,7 @@
|
|
|
35281
35388
|
}
|
|
35282
35389
|
function containedByOpenModal(elements) {
|
|
35283
35390
|
const modalOf = (el) => {
|
|
35284
|
-
const aria = el.closest('[aria-modal="true"]');
|
|
35391
|
+
const aria = el.closest('[aria-modal="true"], mat-dialog-container, .cdk-dialog-container');
|
|
35285
35392
|
if (aria)
|
|
35286
35393
|
return aria;
|
|
35287
35394
|
try {
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
/** A list of drag items under one container. */
|
|
14
|
+
export interface DragGroup {
|
|
15
|
+
/** The drop list, or the items' parent for native drag and drop. */
|
|
16
|
+
container: Element;
|
|
17
|
+
/** The items that can be dragged now (not disabled, not hidden). */
|
|
18
|
+
items: Element[];
|
|
19
|
+
/** True for CDK drag and drop; false for native `draggable="true"`. */
|
|
20
|
+
cdk: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The drag lists in `root`, one per container. CDK items group by their
|
|
24
|
+
* `cdk-drop-list`; native ones by their parent, and only when there are at least
|
|
25
|
+
* two (one draggable on its own is more often an image or file chip to drag
|
|
26
|
+
* out of the page than a list to reorder). A disabled list or item (CDK's
|
|
27
|
+
* `cdk-drop-list-disabled` / `cdk-drag-disabled`) and CDK's drag preview and
|
|
28
|
+
* placeholder are left out.
|
|
29
|
+
*/
|
|
30
|
+
export declare function dragGroups(root: ParentNode, isHidden: (el: Element) => boolean): DragGroup[];
|
|
31
|
+
/**
|
|
32
|
+
* Where a keyboard user would start a move for `item`: its CDK drag handles that
|
|
33
|
+
* belong to it (not to a nested drag item), or the item itself.
|
|
34
|
+
*/
|
|
35
|
+
export declare function dragHandles(item: Element): Element[];
|
|
36
|
+
/**
|
|
37
|
+
* True when there's a control near the list whose name says it moves an item
|
|
38
|
+
* ("Move up", "↓", an `arrow_upward` icon): in the list, or in an element next
|
|
39
|
+
* to it such as a toolbar above it. A sibling that holds another drag list is
|
|
40
|
+
* left out, so one list's Move buttons don't vouch for the list beside it. A
|
|
41
|
+
* drag handle doesn't count, even one named "Reorder": whether it works from the
|
|
42
|
+
* keyboard depends on its key handling, which the scan checks separately.
|
|
43
|
+
* `isTabbable` decides whether the keyboard can reach it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function hasMoveControl(container: Element, isTabbable: (el: Element) => boolean): boolean;
|
|
@@ -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
|
-
|
|
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
|
|
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"`),
|
|
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"`),
|
|
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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
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(
|
|
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
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -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,
|
|
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/report/acr.js
CHANGED
|
@@ -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' },
|
|
@@ -68,7 +68,8 @@ export interface ScanPagesOptions {
|
|
|
68
68
|
/**
|
|
69
69
|
* Also run the keyboard layer in-page — heuristic `ngbr/*` findings for
|
|
70
70
|
* keyboard-unreachable controls, click-without-keyboard handlers, hover-only
|
|
71
|
-
* content, and tab-order mismatches (the
|
|
71
|
+
* content, drag and drop with no keyboard way, and tab-order mismatches (the
|
|
72
|
+
* last needs real layout, which headless has).
|
|
72
73
|
* Default false.
|
|
73
74
|
*/
|
|
74
75
|
keyboard?: boolean;
|
package/dist/runner.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ export interface RunOptions {
|
|
|
23
23
|
/**
|
|
24
24
|
* Also run the keyboard layer — heuristic `ngbr/*` findings for
|
|
25
25
|
* keyboard-unreachable controls, click-without-keyboard handlers, hover-only
|
|
26
|
-
* content, and tab-order mismatches.
|
|
26
|
+
* content, drag and drop with no keyboard way, and tab-order mismatches.
|
|
27
|
+
* Default false.
|
|
27
28
|
*/
|
|
28
29
|
keyboard?: boolean;
|
|
29
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
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",
|
|
@@ -74,12 +74,16 @@
|
|
|
74
74
|
"@analogjs/vite-plugin-angular": "^2.8.0",
|
|
75
75
|
"@analogjs/vitest-angular": "^2.8.0",
|
|
76
76
|
"@angular/build": "^22.2.1",
|
|
77
|
+
"@angular/cdk": "^22.2.1",
|
|
77
78
|
"@angular/common": "^22.2.1",
|
|
78
79
|
"@angular/compiler": "^22.2.1",
|
|
79
80
|
"@angular/compiler-cli": "^22.2.1",
|
|
80
81
|
"@angular/core": "^22.2.1",
|
|
82
|
+
"@angular/forms": "^22.2.1",
|
|
81
83
|
"@angular/platform-browser": "^22.2.1",
|
|
82
84
|
"@angular/platform-browser-dynamic": "^22.2.1",
|
|
85
|
+
"@emnapi/core": "^1.11.3",
|
|
86
|
+
"@emnapi/runtime": "^1.11.3",
|
|
83
87
|
"@oxc-project/runtime": "^0.149.0",
|
|
84
88
|
"@types/node": "^26.5.0",
|
|
85
89
|
"jsdom": "^30.0.1",
|