forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocomplete-matches.js
45 lines (38 loc) · 1.33 KB
/
autocomplete-matches.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { text, aria, dom } = axe.commons;
const autocomplete = node.getAttribute('autocomplete');
if (!autocomplete || text.sanitize(autocomplete) === '') {
return false;
}
const nodeName = node.nodeName.toUpperCase();
if (['TEXTAREA', 'INPUT', 'SELECT'].includes(nodeName) === false) {
return false;
}
// The element is an `input` element a `type` of `hidden`, `button`, `submit` or `reset`
const excludedInputTypes = ['submit', 'reset', 'button', 'hidden'];
if (nodeName === 'INPUT' && excludedInputTypes.includes(node.type)) {
return false;
}
// The element has a `disabled` or `aria-disabled="true"` attribute
const ariaDisabled = node.getAttribute('aria-disabled') || 'false';
if (node.disabled || ariaDisabled.toLowerCase() === 'true') {
return false;
}
// The element has `tabindex="-1"` and has a [[semantic role]] that is
// not a [widget](https://www.w3.org/TR/wai-aria-1.1/#widget_roles)
const role = node.getAttribute('role');
const tabIndex = node.getAttribute('tabindex');
if (tabIndex === '-1' && role) {
const roleDef = aria.lookupTable.role[role];
if (roleDef === undefined || roleDef.type !== 'widget') {
return false;
}
}
// The element is **not** visible on the page or exposed to assistive technologies
if (
tabIndex === '-1' &&
!dom.isVisible(node, false) &&
!dom.isVisible(node, true)
) {
return false;
}
return true;