From 806db4b546a9900edd43861cff00434f46afbf7a Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Tue, 7 Nov 2017 17:48:59 -0800 Subject: [PATCH] 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 f439ebb634..ae83de0238 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 faca6291bb..5be3670bb8 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
';