|
1 | 1 | import autocompleteMatches from './autocomplete-matches';
|
2 | 2 |
|
3 |
| -function nodeIsASearchFunctionality(node, currLevel=0, maxLevels=4) { |
4 |
| - if(!node) { |
5 |
| - return false; |
| 3 | +function nodeIsASearchFunctionality(actualNode, currLevel = 0, maxLevels = 4) { |
| 4 | + if (!actualNode) { |
| 5 | + return false; |
6 | 6 | }
|
7 | 7 |
|
8 | 8 | function currentLevelSearch(node, currentLevel) {
|
9 |
| - if(!node || currentLevel > maxLevels) { |
10 |
| - return false; |
11 |
| - } |
| 9 | + if (!node || currentLevel > maxLevels) { |
| 10 | + return false; |
| 11 | + } |
12 | 12 |
|
13 |
| - let details = `\nLevel ${currentLevel}:\n`; |
| 13 | + let details = `\nLevel ${currentLevel}:\n`; |
14 | 14 |
|
15 |
| - //collecting all the HTML attributes |
16 |
| - details += "Attributes:\n"; |
17 |
| - if(node.hasAttributes()) { |
18 |
| - const attributes = axe.utils.getNodeAttributes(node); |
19 |
| - for (let i = 0; i < attributes.length; i++) { |
20 |
| - let attr = attributes[i]; |
21 |
| - details += ` ${attr.name}: ${attr.value}\n`; |
22 |
| - } |
| 15 | + //collecting all the HTML attributes |
| 16 | + details += 'Attributes:\n'; |
| 17 | + if (node.hasAttributes()) { |
| 18 | + const attributes = axe.utils.getNodeAttributes(node); |
| 19 | + for (let i = 0; i < attributes.length; i++) { |
| 20 | + const attr = attributes[i]; |
| 21 | + details += ` ${attr.name}: ${attr.value}\n`; |
23 | 22 | }
|
24 |
| - |
25 |
| - // Collect any associated labels (if node is an input, select, textarea, etc.) |
26 |
| - if (node.labels) { |
27 |
| - details += "Labels:\n"; |
28 |
| - for (let j = 0; j < node.labels.length; j++) { |
29 |
| - details += ` ${node.labels[j].innerText}\n`; |
30 |
| - } |
31 |
| - } else if (node.nodeName.toLowerCase() === 'input' && node.type !== 'hidden') { |
32 |
| - let labels = document.querySelectorAll('label[for="' + node.id + '"]'); |
33 |
| - details += "Labels:\n"; |
34 |
| - labels.forEach(label => { |
35 |
| - details += ` ${label.innerText}\n`; |
36 |
| - }); |
| 23 | + } |
| 24 | + |
| 25 | + // Collect any associated labels (if node is an input, select, textarea, etc.) |
| 26 | + if (node.labels) { |
| 27 | + details += 'Labels:\n'; |
| 28 | + for (let j = 0; j < node.labels.length; j++) { |
| 29 | + details += ` ${node.labels[j].innerText}\n`; |
37 | 30 | }
|
| 31 | + } else if ( |
| 32 | + node.nodeName.toLowerCase() === 'input' && |
| 33 | + node.type !== 'hidden' |
| 34 | + ) { |
| 35 | + const labels = document.querySelectorAll('label[for="' + node.id + '"]'); |
| 36 | + details += 'Labels:\n'; |
| 37 | + labels.forEach(label => { |
| 38 | + details += ` ${label.innerText}\n`; |
| 39 | + }); |
| 40 | + } |
38 | 41 |
|
39 |
| - // Collect the given id |
40 |
| - details += `ID: ${node.id}\n`; |
41 |
| - // Collect all class names |
42 |
| - details += `Class Names: ${node.className.split(' ').filter(name => name).join(', ')}\n`; |
| 42 | + // Collect the given id |
| 43 | + details += `ID: ${node.id}\n`; |
| 44 | + // Collect all class names |
| 45 | + details += `Class Names: ${node.className |
| 46 | + .split(' ') |
| 47 | + .filter(name => name) |
| 48 | + .join(', ')}\n`; |
43 | 49 |
|
44 |
| - const regex = new RegExp('search', 'i'); |
45 |
| - if(regex.test(details)) { |
46 |
| - return true; |
47 |
| - } else { |
48 |
| - return currentLevelSearch(node.parentElement, currentLevel + 1); |
49 |
| - } |
| 50 | + const regex = new RegExp('search', 'i'); |
| 51 | + if (regex.test(details)) { |
| 52 | + return true; |
| 53 | + } else { |
| 54 | + return currentLevelSearch(node.parentElement, currentLevel + 1); |
| 55 | + } |
50 | 56 | }
|
51 |
| - return currentLevelSearch(node, currLevel); |
| 57 | + return currentLevelSearch(actualNode, currLevel); |
52 | 58 | }
|
53 | 59 |
|
54 |
| -function autocompleteA11yMatches(node, virtualNode) { |
| 60 | +function autocompleteA11yMatches(node, virtualNode) { |
55 | 61 | const a11yEngineFlag = true;
|
56 | 62 | /* the flag is used to tell autocomplete matcher that it is being called
|
57 | 63 | by a11y-engine and thus bypass an if block
|
58 | 64 | The second condition is to check we are not matching with search functionality */
|
59 |
| - return (autocompleteMatches(node, virtualNode, a11yEngineFlag) && !nodeIsASearchFunctionality(node)); |
| 65 | + return ( |
| 66 | + autocompleteMatches(node, virtualNode, a11yEngineFlag) && |
| 67 | + !nodeIsASearchFunctionality(node) |
| 68 | + ); |
60 | 69 | }
|
61 | 70 |
|
62 | 71 | export default autocompleteA11yMatches;
|
0 commit comments