From 5dadee20932584a72164d06f3e51493ef40c0cd5 Mon Sep 17 00:00:00 2001 From: Arjun Chikara <106317740+chikara1608@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:10:44 +0530 Subject: [PATCH] Fix: Autocomplete enhancement quantity field removed (#121) * autocomplete enhancement quantity field removed: * minor comment addressed --- lib/rules/autocomplete-a11y-matches.js | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/rules/autocomplete-a11y-matches.js b/lib/rules/autocomplete-a11y-matches.js index e6c7e61e..e788e278 100644 --- a/lib/rules/autocomplete-a11y-matches.js +++ b/lib/rules/autocomplete-a11y-matches.js @@ -57,6 +57,41 @@ function nodeIsASearchFunctionality(actualNode, currLevel = 0, maxLevels = 4) { return currentLevelSearch(actualNode, currLevel); } +function quantityField(node) { + const keywords = [ + 'qty', + 'quantity', + 'quantities', + 'km', + 'kilometer', + 'drive', + 'code', + 'mileage', + 'power', + 'fuel' + ]; + const attributes = [ + 'name', + 'id', + 'title', + 'placeholder', + 'aria-label', + 'data-label', + 'data-title', + 'data-placeholder', + 'role' + ]; + return attributes.some(attr => { + if (node.hasAttribute(attr)) { + const value = node.getAttribute(attr).toLowerCase(); + return keywords.some( + keyword => value && value.includes(keyword.toLowerCase()) + ); + } + return false; + }); +} + function autocompleteA11yMatches(node, virtualNode) { const a11yEngineFlag = true; /* the flag is used to tell autocomplete matcher that it is being called @@ -64,7 +99,8 @@ function autocompleteA11yMatches(node, virtualNode) { The second condition is to check we are not matching with search functionality */ return ( autocompleteMatches(node, virtualNode, a11yEngineFlag) && - !nodeIsASearchFunctionality(node) + !nodeIsASearchFunctionality(node) && + !quantityField(node) ); }