-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathautocomplete-matches.js
More file actions
78 lines (69 loc) · 2.18 KB
/
autocomplete-matches.js
File metadata and controls
78 lines (69 loc) · 2.18 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { sanitize } from '../commons/text';
import standards from '../standards';
import { isVisibleToScreenReaders, isVisibleOnScreen } from '../commons/dom';
import { parseTabindex } from '../core/utils';
import { getExplicitRole } from '../commons/aria';
function autocompleteMatches(node, virtualNode, flag = false) {
const autocomplete = virtualNode.attr('autocomplete');
if ((!autocomplete || sanitize(autocomplete) === '') && !flag) {
return false;
}
const nodeName = virtualNode.props.nodeName;
if (['textarea', 'input', 'select'].includes(nodeName) === false) {
return false;
}
// The element has a `readonly` or `aria-readonly="true"` attribute
const ariaReadonly = virtualNode.attr('aria-readonly') || 'false';
if (
virtualNode.hasAttr('readonly') ||
ariaReadonly.toLowerCase() === 'true'
) {
return false;
}
// The element is an `input` element a `type` of `hidden`, `button`, `submit` or `reset`
const excludedInputTypes = [
'submit',
'reset',
'button',
'hidden',
'checkbox',
'file',
'image',
'radio'
];
if (
nodeName === 'input' &&
excludedInputTypes.includes(virtualNode.props.type)
) {
return false;
}
// The element has a `disabled` or `aria-disabled="true"` attribute
const ariaDisabled = virtualNode.attr('aria-disabled') || 'false';
if (
virtualNode.hasAttr('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 = getExplicitRole(virtualNode);
const tabIndex = parseTabindex(virtualNode.attr('tabindex'));
if (tabIndex < 0 && virtualNode.hasAttr('role')) {
const roleDef = standards.ariaRoles[role];
if (roleDef === undefined || roleDef.type !== 'widget') {
return false;
}
}
// The element is **not** visible on the page or exposed to assistive technologies
if (
tabIndex < 0 &&
virtualNode.actualNode &&
!isVisibleOnScreen(virtualNode) &&
!isVisibleToScreenReaders(virtualNode)
) {
return false;
}
return true;
}
export default autocompleteMatches;