@ngbracket/a11y-devtools 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to `@ngbracket/a11y-devtools` are documented here.
|
|
4
4
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 0.15.2
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- **`ngbr/unreachable-control` no longer flags items that arrow keys reach.**
|
|
11
|
+
In a composite widget (a tab list, toolbar, menu, menubar, radio group,
|
|
12
|
+
listbox, tree, treegrid or grid), Tab reaches the widget once and arrow keys
|
|
13
|
+
move between its items, so the other items are correctly out of the tab
|
|
14
|
+
order. They were reported as serious. An item is now skipped when the widget
|
|
15
|
+
(or a combobox that controls it) uses `aria-activedescendant`, or when the
|
|
16
|
+
item has a `tabindex` and Tab can get into the widget: one item is tabbable,
|
|
17
|
+
the widget is, or another element controls it (a menu button). A widget Tab
|
|
18
|
+
can't enter at all, and an item script can't focus, are still reported.
|
|
19
|
+
Found on our own docs: 9 false positives across the listbox, tree and
|
|
20
|
+
selectable-list pages.
|
|
21
|
+
|
|
22
|
+
## 0.15.1
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **Collapsed sidebars no longer cause false tab-order findings.** A
|
|
27
|
+
`<details>` nested inside a closed `<details>` (a group inside a collapsed
|
|
28
|
+
sidebar section) had its summary counted as a tab stop, although it's hidden
|
|
29
|
+
and Tab can't reach it. The next section's summary then looked like a jump
|
|
30
|
+
back up the page, so `ngbr/tab-order-mismatch` fired once per section. Every
|
|
31
|
+
closed `<details>` up the tree now counts. This also fixes the tab-order
|
|
32
|
+
badges in the overlay. Found on our own docs site.
|
|
33
|
+
- **`ngbr/unreachable-control` skips hidden controls.** A custom control inside
|
|
34
|
+
a closed `<details>`, a `[hidden]` or `inert` subtree, or `display: none` was
|
|
35
|
+
reported as unreachable. Tab can't reach it because it isn't shown, which
|
|
36
|
+
isn't a problem; it's checked once it's shown.
|
|
37
|
+
|
|
6
38
|
## 0.15.0
|
|
7
39
|
|
|
8
40
|
### Added
|
package/dist/inpage.global.js
CHANGED
|
@@ -7129,7 +7129,7 @@
|
|
|
7129
7129
|
isContextSpec: function isContextSpec() {
|
|
7130
7130
|
return _isContextSpec;
|
|
7131
7131
|
},
|
|
7132
|
-
isHidden: function
|
|
7132
|
+
isHidden: function isHidden3() {
|
|
7133
7133
|
return is_hidden_default;
|
|
7134
7134
|
},
|
|
7135
7135
|
isHtmlElement: function isHtmlElement() {
|
|
@@ -19809,7 +19809,7 @@
|
|
|
19809
19809
|
function _isLabelledShadowDomSelector(selector) {
|
|
19810
19810
|
return _objectHasOwn(selector, "fromShadowDom");
|
|
19811
19811
|
}
|
|
19812
|
-
function
|
|
19812
|
+
function isHidden2(el, recursed) {
|
|
19813
19813
|
var node = get_node_from_tree_default(el);
|
|
19814
19814
|
if (el.nodeType === 9) {
|
|
19815
19815
|
return false;
|
|
@@ -19825,13 +19825,13 @@
|
|
|
19825
19825
|
return true;
|
|
19826
19826
|
}
|
|
19827
19827
|
var parent = el.assignedSlot ? el.assignedSlot : el.parentNode;
|
|
19828
|
-
var hidden =
|
|
19828
|
+
var hidden = isHidden2(parent, true);
|
|
19829
19829
|
if (node) {
|
|
19830
19830
|
node._isHidden = hidden;
|
|
19831
19831
|
}
|
|
19832
19832
|
return hidden;
|
|
19833
19833
|
}
|
|
19834
|
-
var is_hidden_default =
|
|
19834
|
+
var is_hidden_default = isHidden2;
|
|
19835
19835
|
function _isHtmlElement(node) {
|
|
19836
19836
|
var _node$props$nodeName, _node$props;
|
|
19837
19837
|
var nodeName2 = (_node$props$nodeName = (_node$props = node.props) === null || _node$props === void 0 ? void 0 : _node$props.nodeName) !== null && _node$props$nodeName !== void 0 ? _node$props$nodeName : node.nodeName.toLowerCase();
|
|
@@ -34653,6 +34653,9 @@
|
|
|
34653
34653
|
function hasFocusableDescendant(element) {
|
|
34654
34654
|
return element.querySelector(FOCUSABLE_SELECTOR) !== null;
|
|
34655
34655
|
}
|
|
34656
|
+
function hasTabbableDescendant(element, isVisible = defaultIsVisible) {
|
|
34657
|
+
return [...element.querySelectorAll(FOCUSABLE_SELECTOR)].some((el) => isTabbable(el, isVisible));
|
|
34658
|
+
}
|
|
34656
34659
|
function nativeTabIndex(element) {
|
|
34657
34660
|
return isNativelyFocusable(element) ? 0 : -1;
|
|
34658
34661
|
}
|
|
@@ -34696,8 +34699,14 @@
|
|
|
34696
34699
|
function isStructurallyHidden(element) {
|
|
34697
34700
|
if (element.closest("[inert]") || element.closest("[hidden]"))
|
|
34698
34701
|
return true;
|
|
34699
|
-
|
|
34700
|
-
|
|
34702
|
+
for (let details = element.closest("details:not([open])"); details; details = details.parentElement?.closest("details:not([open])") ?? null) {
|
|
34703
|
+
if (details === element)
|
|
34704
|
+
continue;
|
|
34705
|
+
const summary = [...details.children].find((child) => child.tagName.toLowerCase() === "summary");
|
|
34706
|
+
if (!summary?.contains(element))
|
|
34707
|
+
return true;
|
|
34708
|
+
}
|
|
34709
|
+
return false;
|
|
34701
34710
|
}
|
|
34702
34711
|
function defaultIsVisible(element) {
|
|
34703
34712
|
const view = element.ownerDocument?.defaultView;
|
|
@@ -34712,6 +34721,9 @@
|
|
|
34712
34721
|
}
|
|
34713
34722
|
return true;
|
|
34714
34723
|
}
|
|
34724
|
+
function isHidden(element, isVisible = defaultIsVisible) {
|
|
34725
|
+
return isStructurallyHidden(element) || !isVisible(element);
|
|
34726
|
+
}
|
|
34715
34727
|
function isTabbable(element, isVisible = defaultIsVisible) {
|
|
34716
34728
|
if (resolvedTabIndex(element) < 0)
|
|
34717
34729
|
return false;
|
|
@@ -34822,6 +34834,19 @@
|
|
|
34822
34834
|
"treeitem"
|
|
34823
34835
|
]);
|
|
34824
34836
|
var KEY_EVENTS = ["keydown", "keyup", "keypress"];
|
|
34837
|
+
var COMPOSITE_SELECTOR = ["tablist", "toolbar", "menu", "menubar", "radiogroup", "listbox", "tree", "treegrid", "grid"].map((role) => `[role="${role}"]`).join(",");
|
|
34838
|
+
function reachedWithinWidget(element, isVisible) {
|
|
34839
|
+
const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
|
|
34840
|
+
if (!widget)
|
|
34841
|
+
return false;
|
|
34842
|
+
const controllers = widget.id ? [...(widget.ownerDocument ?? document).querySelectorAll("[aria-controls], [aria-owns]")].filter((el) => `${el.getAttribute("aria-controls") ?? ""} ${el.getAttribute("aria-owns") ?? ""}`.split(/\s+/).includes(widget.id)) : [];
|
|
34843
|
+
if ([widget, ...controllers].some((el) => el.hasAttribute("aria-activedescendant")))
|
|
34844
|
+
return true;
|
|
34845
|
+
const tabindex = element.getAttribute("tabindex");
|
|
34846
|
+
if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
|
|
34847
|
+
return false;
|
|
34848
|
+
return isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
|
|
34849
|
+
}
|
|
34825
34850
|
var RULE_DOCS = "https://ngbracket.com/tools/a11y-devtools/docs";
|
|
34826
34851
|
function shortSelector(element) {
|
|
34827
34852
|
const tag = element.tagName.toLowerCase();
|
|
@@ -34867,8 +34892,12 @@
|
|
|
34867
34892
|
continue;
|
|
34868
34893
|
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
34869
34894
|
continue;
|
|
34895
|
+
if (isHidden(element, isVisible))
|
|
34896
|
+
continue;
|
|
34870
34897
|
const focusable = isTabbable(element, isVisible);
|
|
34871
34898
|
if (!focusable) {
|
|
34899
|
+
if (interactiveByRole && reachedWithinWidget(element, isVisible))
|
|
34900
|
+
continue;
|
|
34872
34901
|
const reason = interactiveByRole ? `has role="${role}"` : "has a click handler";
|
|
34873
34902
|
findings.push(make(element, "ngbr/unreachable-control", "serious", `Keyboard users can't reach this control: it ${reason}, but it isn't a native control and has no tabindex="0", so Tab skips it. Use a <button> or <a href>, or add tabindex="0" and Enter/Space handling.`, `${RULE_DOCS}/unreachable-control`));
|
|
34874
34903
|
continue;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* confirmed failures.
|
|
13
13
|
*/
|
|
14
14
|
import { appComponentFromPath, DEFAULT_FRAMEWORK_PREFIXES, resolveComponentPath, resolveDirectiveNames, resolveListenerEvents, } from '../attribution.js';
|
|
15
|
-
import { hasFocusableDescendant, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
15
|
+
import { hasFocusableDescendant, hasTabbableDescendant, isHidden, isNativelyFocusable, isTabbable, tabSequence, visualOrderJumps, } from './tab-sequence.js';
|
|
16
16
|
import { findUncontainedModals } from './focus-trap.js';
|
|
17
17
|
import { blockingModalDialog } from '../top-layer.js';
|
|
18
18
|
/** WAI-ARIA roles that make a non-native element behave as an interactive control. */
|
|
@@ -35,6 +35,40 @@ const INTERACTIVE_ROLES = new Set([
|
|
|
35
35
|
'treeitem',
|
|
36
36
|
]);
|
|
37
37
|
const KEY_EVENTS = ['keydown', 'keyup', 'keypress'];
|
|
38
|
+
/**
|
|
39
|
+
* Composite widgets: Tab reaches the widget once, and arrow keys move between
|
|
40
|
+
* its items (WAI-ARIA APG "Keyboard navigation inside components").
|
|
41
|
+
*/
|
|
42
|
+
const COMPOSITE_SELECTOR = ['tablist', 'toolbar', 'menu', 'menubar', 'radiogroup', 'listbox', 'tree', 'treegrid', 'grid']
|
|
43
|
+
.map((role) => `[role="${role}"]`)
|
|
44
|
+
.join(',');
|
|
45
|
+
/**
|
|
46
|
+
* True when `element` is an item that its composite widget reaches with arrow
|
|
47
|
+
* keys, so Tab skipping it is correct:
|
|
48
|
+
* - **aria-activedescendant**: focus stays on the widget (or on a combobox that
|
|
49
|
+
* controls it) and points at the item; or
|
|
50
|
+
* - **roving tabindex**: the item has a tabindex (usually -1), so script can
|
|
51
|
+
* focus it, and Tab can get into the widget: one of its items is tabbable,
|
|
52
|
+
* the widget itself is, or another element controls it (a menu or listbox
|
|
53
|
+
* popup, which gets focus when it opens).
|
|
54
|
+
* An item with neither, or a widget Tab can't enter at all, is still reported.
|
|
55
|
+
*/
|
|
56
|
+
function reachedWithinWidget(element, isVisible) {
|
|
57
|
+
const widget = element.parentElement?.closest(COMPOSITE_SELECTOR);
|
|
58
|
+
if (!widget)
|
|
59
|
+
return false;
|
|
60
|
+
const controllers = widget.id
|
|
61
|
+
? [...(widget.ownerDocument ?? document).querySelectorAll('[aria-controls], [aria-owns]')].filter((el) => `${el.getAttribute('aria-controls') ?? ''} ${el.getAttribute('aria-owns') ?? ''}`
|
|
62
|
+
.split(/\s+/)
|
|
63
|
+
.includes(widget.id))
|
|
64
|
+
: [];
|
|
65
|
+
if ([widget, ...controllers].some((el) => el.hasAttribute('aria-activedescendant')))
|
|
66
|
+
return true;
|
|
67
|
+
const tabindex = element.getAttribute('tabindex');
|
|
68
|
+
if (tabindex === null || Number.isNaN(Number.parseInt(tabindex, 10)))
|
|
69
|
+
return false;
|
|
70
|
+
return isTabbable(widget, isVisible) || controllers.length > 0 || hasTabbableDescendant(widget, isVisible);
|
|
71
|
+
}
|
|
38
72
|
/**
|
|
39
73
|
* Each rule's page: what the message means, who it affects, exactly what
|
|
40
74
|
* triggers it, how to fix and check it, and the WCAG/APG reference.
|
|
@@ -103,8 +137,14 @@ export function scanKeyboard(root = document, options = {}) {
|
|
|
103
137
|
// the keyboard reaches.
|
|
104
138
|
if (!interactiveByRole && hasFocusableDescendant(element))
|
|
105
139
|
continue;
|
|
140
|
+
// Hidden (a closed <details>, [hidden], display:none): not reachable because
|
|
141
|
+
// it isn't shown. Check it when it is.
|
|
142
|
+
if (isHidden(element, isVisible))
|
|
143
|
+
continue;
|
|
106
144
|
const focusable = isTabbable(element, isVisible);
|
|
107
145
|
if (!focusable) {
|
|
146
|
+
if (interactiveByRole && reachedWithinWidget(element, isVisible))
|
|
147
|
+
continue;
|
|
108
148
|
const reason = interactiveByRole ? `has role="${role}"` : 'has a click handler';
|
|
109
149
|
findings.push(make(element, 'ngbr/unreachable-control', 'serious', `Keyboard users can't reach this control: it ${reason}, but it isn't a native ` +
|
|
110
150
|
`control and has no tabindex="0", so Tab skips it. Use a <button> or <a href>, ` +
|
|
@@ -45,6 +45,8 @@ export declare function isFocusSentinel(el: Element): boolean;
|
|
|
45
45
|
* event delegation — handling clicks on the controls inside — not a fake button.
|
|
46
46
|
*/
|
|
47
47
|
export declare function hasFocusableDescendant(element: Element): boolean;
|
|
48
|
+
/** True when something inside `element` is reachable with Tab. */
|
|
49
|
+
export declare function hasTabbableDescendant(element: Element, isVisible?: (el: Element) => boolean): boolean;
|
|
48
50
|
/**
|
|
49
51
|
* True when the element takes focus without an explicit `tabindex` — a link with
|
|
50
52
|
* an href, a form control, a `<summary>`, an editing host, and the embedded
|
|
@@ -57,6 +59,12 @@ export declare function isNativelyFocusable(element: Element): boolean;
|
|
|
57
59
|
* `tabindex="foo"`) is ignored by browsers, so it falls back to the native value.
|
|
58
60
|
*/
|
|
59
61
|
export declare function resolvedTabIndex(element: Element): number;
|
|
62
|
+
/**
|
|
63
|
+
* True when `element` isn't shown at all: structurally hidden (see
|
|
64
|
+
* {@link isStructurallyHidden}) or hidden by layout. A hidden control is out of
|
|
65
|
+
* the tab order because nobody can see it, not because it's unreachable.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isHidden(element: Element, isVisible?: (el: Element) => boolean): boolean;
|
|
60
68
|
/**
|
|
61
69
|
* True when `element` participates in sequential keyboard navigation: it's
|
|
62
70
|
* focusable, has a resolved `tabindex >= 0`, and is neither disabled nor hidden.
|
|
@@ -71,6 +71,10 @@ const FOCUSABLE_SELECTOR = [
|
|
|
71
71
|
export function hasFocusableDescendant(element) {
|
|
72
72
|
return element.querySelector(FOCUSABLE_SELECTOR) !== null;
|
|
73
73
|
}
|
|
74
|
+
/** True when something inside `element` is reachable with Tab. */
|
|
75
|
+
export function hasTabbableDescendant(element, isVisible = defaultIsVisible) {
|
|
76
|
+
return [...element.querySelectorAll(FOCUSABLE_SELECTOR)].some((el) => isTabbable(el, isVisible));
|
|
77
|
+
}
|
|
74
78
|
/** A native default of 0 (focusable without a tabindex attribute), else -1. */
|
|
75
79
|
function nativeTabIndex(element) {
|
|
76
80
|
return isNativelyFocusable(element) ? 0 : -1;
|
|
@@ -129,12 +133,23 @@ function isDisabled(element) {
|
|
|
129
133
|
* layout: inside an `[inert]` or `[hidden]` subtree, or non-summary content of a
|
|
130
134
|
* closed `<details>`. Kept separate from the layout check so the injectable
|
|
131
135
|
* visibility predicate only ever overrides computed-style visibility.
|
|
136
|
+
*
|
|
137
|
+
* Every closed `<details>` up the tree counts, not just the nearest: a nested
|
|
138
|
+
* `<details>` (a sidebar group inside a collapsed section) has its own summary,
|
|
139
|
+
* but that summary is hidden too while an outer one is closed.
|
|
132
140
|
*/
|
|
133
141
|
function isStructurallyHidden(element) {
|
|
134
142
|
if (element.closest('[inert]') || element.closest('[hidden]'))
|
|
135
143
|
return true;
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
for (let details = element.closest('details:not([open])'); details; details = details.parentElement?.closest('details:not([open])') ?? null) {
|
|
145
|
+
if (details === element)
|
|
146
|
+
continue;
|
|
147
|
+
// Only this <details>' own summary (its first <summary> child) stays shown.
|
|
148
|
+
const summary = [...details.children].find((child) => child.tagName.toLowerCase() === 'summary');
|
|
149
|
+
if (!summary?.contains(element))
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
138
153
|
}
|
|
139
154
|
/** Layout-aware default visibility: computed `display`/`visibility` up the tree. */
|
|
140
155
|
function defaultIsVisible(element) {
|
|
@@ -150,6 +165,14 @@ function defaultIsVisible(element) {
|
|
|
150
165
|
}
|
|
151
166
|
return true;
|
|
152
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* True when `element` isn't shown at all: structurally hidden (see
|
|
170
|
+
* {@link isStructurallyHidden}) or hidden by layout. A hidden control is out of
|
|
171
|
+
* the tab order because nobody can see it, not because it's unreachable.
|
|
172
|
+
*/
|
|
173
|
+
export function isHidden(element, isVisible = defaultIsVisible) {
|
|
174
|
+
return isStructurallyHidden(element) || !isVisible(element);
|
|
175
|
+
}
|
|
153
176
|
/**
|
|
154
177
|
* True when `element` participates in sequential keyboard navigation: it's
|
|
155
178
|
* focusable, has a resolved `tabindex >= 0`, and is neither disabled nor hidden.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Dev-only in-app accessibility auditing for Angular that maps each axe violation back to the component that rendered it — the attribution React overlay tools can't do.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Duncan Faulkner",
|