diff --git a/lib/checks/label/explicit-evaluate.js b/lib/checks/label/explicit-evaluate.js index d3410c2124..fadb1af36c 100644 --- a/lib/checks/label/explicit-evaluate.js +++ b/lib/checks/label/explicit-evaluate.js @@ -2,22 +2,26 @@ import { getRootNode, isVisible } from '../../commons/dom'; import { accessibleText } from '../../commons/text'; import { escapeSelector } from '../../core/utils'; -function explicitEvaluate(node) { - if (node.getAttribute('id')) { - const root = getRootNode(node); - const id = escapeSelector(node.getAttribute('id')); - const label = root.querySelector(`label[for="${id}"]`); +function explicitEvaluate(node, options, virtualNode) { + try { + if (virtualNode.attr('id')) { + const root = getRootNode(virtualNode.actualNode); + const id = escapeSelector(virtualNode.attr('id')); + const label = root.querySelector(`label[for="${id}"]`); - if (label) { - // defer to hidden-explicit-label check for better messaging - if (!isVisible(label)) { - return true; - } else { - return !!accessibleText(label); + if (label) { + // defer to hidden-explicit-label check for better messaging + if (!isVisible(label)) { + return true; + } else { + return !!accessibleText(label); + } } } + return false; + } catch (e) { + return undefined; } - return false; } export default explicitEvaluate; diff --git a/lib/checks/label/explicit.json b/lib/checks/label/explicit.json index defced373b..511b68c4d0 100644 --- a/lib/checks/label/explicit.json +++ b/lib/checks/label/explicit.json @@ -5,7 +5,8 @@ "impact": "critical", "messages": { "pass": "Form element has an explicit