Skip to content

Commit 3f4535a

Browse files
committed
Added a range to colour contrast alpha checks before adding a warning (accounts for bg alpha 0). Added unit tests for error varieties. #pr134 is failing in the unit test but passing in the browser, it may be a phantomjs quirk.
1 parent 5086fe6 commit 3f4535a

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3_Contrast = {
119119
parent = parent.parentNode;
120120
}//end while
121121

122-
if (bgColour && HTMLCS.util.colourStrToRGB(bgColour).alpha < 1.0) {
122+
var bgAlpha = HTMLCS.util.colourStrToRGB(bgColour).alpha;
123+
var fgAlpha = HTMLCS.util.colourStrToRGB(foreColour).alpha;
124+
125+
if (bgColour && bgAlpha < 1.0 && bgAlpha > 0) {
123126
// If we have a rgba background colour, skip the contrast ratio checks,
124127
// and push a warning instead.
125128
failures.push({
@@ -131,7 +134,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3_Contrast = {
131134
hasAlpha: true,
132135
});
133136
continue;
134-
} else if (foreColour && HTMLCS.util.colourStrToRGB(foreColour).alpha < 1.0) {
137+
} else if (foreColour && fgAlpha < 1.0 && fgAlpha > 0) {
135138
// If we have a rgba fore colour, skip the contrast ratio checks,
136139
// and push a warning instead.
137140
failures.push({

Tests/WCAG2/1_4_3_Contrast.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Standard: WCAG2AA
88
Assert: Error *.G18.Fail on #basicContrastFail
99
Assert: No Error *.G18 on #issue155
10+
Assert: Warning *.G145.Alpha on #rgba
11+
Assert: Warning *.G18.Alpha on #rgba2
1012
-->
1113
</head>
1214
<body>
@@ -15,7 +17,14 @@
1517

1618
<p>Sample: <span id="issue155" style="color: #7c7cff; background-color: #ffffff; font-size: 14pt; font-weight: bold;">I am 14pt bold text and should pass</span></p>
1719

18-
<p>Warning: <span id="pr134" style="color: #7c7cff; background-color: #0000000C; font-size: 14pt; font-weight: bold;">I am 14pt bold text on a transparent background and should generate a warning</span></p>
20+
<div>Warning: <div id="pr134" style="color: #7c7cff; background-color: #0000000C; font-size: 14pt; font-weight: bold;">I am 14pt bold text on a transparent background and should generate a warning</div></div>
21+
22+
<div>Warning RGBA: <div id="rgba" style="color: #7c7cff; background-color: rgba(0,0,0,0.5); font-size: 14pt; font-weight: bold;">I am 14pt bold text on a transparent background and should generate a warning</div></div>
23+
24+
<div style="background-color: #ccc">
25+
<span>Warning RBGA in BG</span>
26+
<div id="rgba2" style="background-color: rgba(0,0,0,0.2);">Text</div>
27+
</div>
1928

2029
</body>
2130
</html>

0 commit comments

Comments
 (0)