Skip to content

Commit 3b65eec

Browse files
authored
fix(color-contrast): properly pass options to check (#2033)
1 parent 504d912 commit 3b65eec

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

lib/checks/color/color-contrast.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ if (!dom.isVisible(node, false)) {
66

77
const visibleText = text.visibleVirtual(virtualNode, false, true);
88
const ignoreUnicode = !!(options || {}).ignoreUnicode;
9-
const textContainsOnlyUnicode = !text.sanitize(
10-
text.removeUnicode(visibleText, {
11-
emoji: false,
12-
nonBmp: true,
13-
punctuations: false
14-
})
15-
).length;
9+
const textContainsOnlyUnicode =
10+
text.hasUnicode(visibleText, {
11+
nonBmp: true
12+
}) &&
13+
text.sanitize(
14+
text.removeUnicode(visibleText, {
15+
nonBmp: true
16+
})
17+
) === '';
1618

1719
if (textContainsOnlyUnicode && ignoreUnicode) {
1820
this.data({ messageKey: 'nonBmp' });

lib/checks/color/color-contrast.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"id": "color-contrast",
33
"evaluate": "color-contrast.js",
4+
"options": {
5+
"noScroll": false,
6+
"ignoreUnicode": true,
7+
"ignoreLength": false
8+
},
49
"metadata": {
510
"impact": "serious",
6-
"options": {
7-
"noScroll": false,
8-
"ignoreUnicode": true,
9-
"ignoreLength": false
10-
},
1111
"messages": {
1212
"pass": "Element has sufficient color contrast of ${data.contrastRatio}",
1313
"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}",

lib/rules/color-contrast.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"id": "color-contrast",
33
"matches": "color-contrast-matches.js",
44
"excludeHidden": false,
5-
"options": {
6-
"noScroll": false,
7-
"ignoreUnicode": true,
8-
"ignoreLength": false
9-
},
105
"tags": ["cat.color", "wcag2aa", "wcag143"],
116
"metadata": {
127
"description": "Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds",

test/integration/rules/color-contrast/color-contrast.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,9 @@
219219
Hi
220220
</div>
221221
</div>
222+
223+
<div style="background-color: #FFF;">
224+
<div id="canttell20" style="color:#DDD;">
225+
&#x20A0; &#x20A1; &#x20A2; &#x20A3;
226+
</div>
227+
</div>

test/integration/rules/color-contrast/color-contrast.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
["#canttell16"],
3131
["#canttell17"],
3232
["#canttell18"],
33-
["#canttell19"]
33+
["#canttell19"],
34+
["#canttell20"]
3435
]
3536
}

0 commit comments

Comments
 (0)