Skip to content

Commit 5dadee2

Browse files
authored
Fix: Autocomplete enhancement quantity field removed (#121)
* autocomplete enhancement quantity field removed: * minor comment addressed
1 parent a1eed77 commit 5dadee2

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/rules/autocomplete-a11y-matches.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,50 @@ function nodeIsASearchFunctionality(actualNode, currLevel = 0, maxLevels = 4) {
5757
return currentLevelSearch(actualNode, currLevel);
5858
}
5959

60+
function quantityField(node) {
61+
const keywords = [
62+
'qty',
63+
'quantity',
64+
'quantities',
65+
'km',
66+
'kilometer',
67+
'drive',
68+
'code',
69+
'mileage',
70+
'power',
71+
'fuel'
72+
];
73+
const attributes = [
74+
'name',
75+
'id',
76+
'title',
77+
'placeholder',
78+
'aria-label',
79+
'data-label',
80+
'data-title',
81+
'data-placeholder',
82+
'role'
83+
];
84+
return attributes.some(attr => {
85+
if (node.hasAttribute(attr)) {
86+
const value = node.getAttribute(attr).toLowerCase();
87+
return keywords.some(
88+
keyword => value && value.includes(keyword.toLowerCase())
89+
);
90+
}
91+
return false;
92+
});
93+
}
94+
6095
function autocompleteA11yMatches(node, virtualNode) {
6196
const a11yEngineFlag = true;
6297
/* the flag is used to tell autocomplete matcher that it is being called
6398
by a11y-engine and thus bypass an if block
6499
The second condition is to check we are not matching with search functionality */
65100
return (
66101
autocompleteMatches(node, virtualNode, a11yEngineFlag) &&
67-
!nodeIsASearchFunctionality(node)
102+
!nodeIsASearchFunctionality(node) &&
103+
!quantityField(node)
68104
);
69105
}
70106

0 commit comments

Comments
 (0)