Skip to content

Commit

Permalink
fix(color-contrast): properly pass options to check (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Feb 10, 2020
1 parent ae90dc4 commit 26b99c0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
16 changes: 9 additions & 7 deletions lib/checks/color/color-contrast.js
Expand Up @@ -6,13 +6,15 @@ if (!dom.isVisible(node, false)) {

const visibleText = text.visibleVirtual(virtualNode, false, true);
const ignoreUnicode = !!(options || {}).ignoreUnicode;
const textContainsOnlyUnicode = !text.sanitize(
text.removeUnicode(visibleText, {
emoji: false,
nonBmp: true,
punctuations: false
})
).length;
const textContainsOnlyUnicode =
text.hasUnicode(visibleText, {
nonBmp: true
}) &&
text.sanitize(
text.removeUnicode(visibleText, {
nonBmp: true
})
) === '';

if (textContainsOnlyUnicode && ignoreUnicode) {
this.data({ messageKey: 'nonBmp' });
Expand Down
10 changes: 5 additions & 5 deletions lib/checks/color/color-contrast.json
@@ -1,13 +1,13 @@
{
"id": "color-contrast",
"evaluate": "color-contrast.js",
"options": {
"noScroll": false,
"ignoreUnicode": true,
"ignoreLength": false
},
"metadata": {
"impact": "serious",
"options": {
"noScroll": false,
"ignoreUnicode": true,
"ignoreLength": false
},
"messages": {
"pass": "Element has sufficient color contrast of ${data.contrastRatio}",
"fail": "Element has insufficient color contrast of ${data.contrastRatio} (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected contrast ratio of ${data.expectedContrastRatio}",
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/color-contrast.json
Expand Up @@ -2,11 +2,6 @@
"id": "color-contrast",
"matches": "color-contrast-matches.js",
"excludeHidden": false,
"options": {
"noScroll": false,
"ignoreUnicode": true,
"ignoreLength": false
},
"tags": ["cat.color", "wcag2aa", "wcag143"],
"metadata": {
"description": "Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds",
Expand Down
6 changes: 6 additions & 0 deletions test/integration/rules/color-contrast/color-contrast.html
Expand Up @@ -219,3 +219,9 @@
Hi
</div>
</div>

<div style="background-color: #FFF;">
<div id="canttell20" style="color:#DDD;">
&#x20A0; &#x20A1; &#x20A2; &#x20A3;
</div>
</div>
3 changes: 2 additions & 1 deletion test/integration/rules/color-contrast/color-contrast.json
Expand Up @@ -30,6 +30,7 @@
["#canttell16"],
["#canttell17"],
["#canttell18"],
["#canttell19"]
["#canttell19"],
["#canttell20"]
]
}

0 comments on commit 26b99c0

Please sign in to comment.