diff --git a/lib/commons/color/get-background-color.js b/lib/commons/color/get-background-color.js index a5f61f4b5d..375b1df978 100644 --- a/lib/commons/color/get-background-color.js +++ b/lib/commons/color/get-background-color.js @@ -121,29 +121,35 @@ function elmPartiallyObscured(elm, bgElm, bgColor) { * @param {Element} elm */ function includeMissingElements(elmStack, elm) { - const elementMap = {'TD': 'TR', 'TH': 'THEAD', 'INPUT': 'LABEL'}; + const elementMap = {'TD': ['TR', 'TBODY'], 'TH': ['THEAD'], 'INPUT': ['LABEL']}; const tagArray = elmStack.map((elm) => { return elm.tagName; }); let bgNodes = elmStack; + //jshint maxdepth:7 for (let candidate in elementMap) { if (elementMap.hasOwnProperty(candidate)) { - // tagName matches key - if (elm.tagName === candidate) { - let ancestorMatch = axe.commons.dom.findUp(elm, elementMap[candidate]); - if (ancestorMatch && elmStack.indexOf(ancestorMatch) === -1) { - // found an ancestor not in elmStack, and it overlaps - let overlaps = axe.commons.dom.visuallyOverlaps(elm.getBoundingClientRect(), ancestorMatch); - if (overlaps) { - bgNodes.splice(elmStack.indexOf(elm) + 1, 0, ancestorMatch); + for (let candidateIndex in elementMap[candidate]) { + if (candidate.hasOwnProperty(candidateIndex)) { + + // tagName matches key + if (elm.tagName === candidate) { + let ancestorMatch = axe.commons.dom.findUp(elm, elementMap[candidate][candidateIndex]); + if (ancestorMatch && elmStack.indexOf(ancestorMatch) === -1) { + // found an ancestor not in elmStack, and it overlaps + let overlaps = axe.commons.dom.visuallyOverlaps(elm.getBoundingClientRect(), ancestorMatch); + if (overlaps) { + bgNodes.splice(elmStack.indexOf(elm) + 1, 0, ancestorMatch); + } + } + } + // tagName matches value + // (such as LABEL, when matching itself. It should be in the list, but Phantom skips it) + if (elm.tagName === elementMap[candidate][candidateIndex] && tagArray.indexOf(elm.tagName) === -1) { + bgNodes.splice(tagArray.indexOf(candidate) + 1, 0, elm); } } } - // tagName matches value - // (such as LABEL, when matching itself. It should be in the list, but Phantom skips it) - if (elm.tagName === elementMap[candidate] && tagArray.indexOf(elm.tagName) === -1) { - bgNodes.splice(tagArray.indexOf(candidate) + 1, 0, elm); - } } } return bgNodes; diff --git a/test/checks/color/color-contrast.js b/test/checks/color/color-contrast.js index 28321f22c7..6ebc229360 100644 --- a/test/checks/color/color-contrast.js +++ b/test/checks/color/color-contrast.js @@ -197,6 +197,13 @@ describe('color-contrast', function () { assert.deepEqual(checkContext._relatedNodes, []); }); + it('should return true when there is sufficient contrast based on tbody', function () { + fixture.innerHTML = '
Col 1 |