From c473d976a52f5b530ef2c0e1631acfd3371416ce Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Tue, 7 Nov 2017 17:48:59 -0800 Subject: [PATCH 1/7] fix(color-contrast): incl. elements w/ line breaks Closes https://github.com/dequelabs/axe-core/issues/607 Closes https://github.com/dequelabs/axe-core/issues/556 --- lib/commons/color/get-background-color.js | 3 +++ test/checks/color/color-contrast.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/commons/color/get-background-color.js b/lib/commons/color/get-background-color.js index e63140c085..a472328db5 100644 --- a/lib/commons/color/get-background-color.js +++ b/lib/commons/color/get-background-color.js @@ -121,6 +121,9 @@ function elmPartiallyObscured(elm, bgElm, bgColor) { * @param {Element} elm */ function includeMissingElements(elmStack, elm) { + if (!elmStack.includes(elm)) { + elmStack.unshift(elm); + } const elementMap = {'TD': ['TR', 'TBODY'], 'TH': ['TR', 'THEAD'], 'INPUT': ['LABEL']}; const tagArray = elmStack.map((elm) => { return elm.tagName; diff --git a/test/checks/color/color-contrast.js b/test/checks/color/color-contrast.js index 0e03b6e7b0..138bf7e6c0 100644 --- a/test/checks/color/color-contrast.js +++ b/test/checks/color/color-contrast.js @@ -95,6 +95,21 @@ describe('color-contrast', function () { assert.deepEqual(checkContext._relatedNodes, []); }); + it('should return true for inline elements with sufficient contrast spanning multiple lines', function () { + fixture.innerHTML = '

Text oh heyyyy and here\'s
a link

'; + var target = fixture.querySelector('#target'); + assert.isTrue(checks['color-contrast'].evaluate.call(checkContext, target)); + assert.deepEqual(checkContext._relatedNodes, []); + }); + + it('should return true for inline elements with sufficient contrast', function () { + fixture.innerHTML = '

Text oh heyyyy and here\'s bold text

'; + var target = fixture.querySelector('#target'); + var result = checks['color-contrast'].evaluate.call(checkContext, target); + assert.isTrue(result); + assert.deepEqual(checkContext._relatedNodes, []); + }); + it('should return false when there is not sufficient contrast', function () { fixture.innerHTML = '
' + 'My text
'; From d65df7beef35bd7c1ba31b709a24d4fe78e95d8e Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Tue, 7 Nov 2017 18:23:15 -0800 Subject: [PATCH 2/7] fix(color-contrast): allow disabled label children Closes https://github.com/dequelabs/axe-core/issues/596 --- lib/rules/color-contrast-matches.js | 6 +++++- test/rule-matches/color-contrast-matches.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rules/color-contrast-matches.js b/lib/rules/color-contrast-matches.js index 6377556636..7fbf47be76 100644 --- a/lib/rules/color-contrast-matches.js +++ b/lib/rules/color-contrast-matches.js @@ -35,8 +35,12 @@ if (nodeName === 'FIELDSET' && node.disabled || axe.commons.dom.findUp(node, 'fi var nodeParentLabel = axe.commons.dom.findUp(node, 'label'); if (nodeName === 'LABEL' || nodeParentLabel) { var relevantNode = node; + var relevantVirtualNode = virtualNode; + if (nodeParentLabel) { relevantNode = nodeParentLabel; + // we need an input candidate from a parent to account for label children + relevantVirtualNode = axe.utils.getNodeFromTree(axe._tree[0], nodeParentLabel); } // explicit label of disabled input let doc = axe.commons.dom.getRootNode(relevantNode); @@ -45,7 +49,7 @@ if (nodeName === 'LABEL' || nodeParentLabel) { return false; } - var candidate = axe.utils.querySelectorAll(virtualNode, 'input:not([type="hidden"]):not([type="image"])' + + var candidate = axe.utils.querySelectorAll(relevantVirtualNode, 'input:not([type="hidden"]):not([type="image"])' + ':not([type="button"]):not([type="submit"]):not([type="reset"]), select, textarea'); if (candidate.length && candidate[0].actualNode.disabled) { return false; diff --git a/test/rule-matches/color-contrast-matches.js b/test/rule-matches/color-contrast-matches.js index 77979cad30..a18d6a9ec5 100644 --- a/test/rule-matches/color-contrast-matches.js +++ b/test/rule-matches/color-contrast-matches.js @@ -149,7 +149,18 @@ describe('color-contrast-matches', function () { var target = fixture.querySelector('input'); var tree = axe._tree = axe.utils.getFlattenedTree(fixture); assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(tree[0], target))); + }); + it('should not match a disabled implicit label child', function () { + fixture.innerHTML = ''; + var target = fixture.querySelector('#target'); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + var result = rule.matches(target, axe.utils.getNodeFromTree(tree[0], target)); + assert.isFalse(result); }); it('should not match