Skip to content

Commit 7dcfaf9

Browse files
committed
feature/1.4.1 - Extended rule link-in-text-block
1 parent 34c403f commit 7dcfaf9

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

lib/checks/color/link-in-text-block-evaluate.js

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
incompleteData
77
} from '../../commons/color';
88

9+
import { distinguishableLinkEvaluate } from '../../../../a11y-engine-core/lib/commons/distinguishable-link';
10+
911
function getContrast(color1, color2) {
1012
var c1lum = color1.getRelativeLuminance();
1113
var c2lum = color2.getRelativeLuminance();
@@ -26,6 +28,7 @@ function isBlock(elm) {
2628
}
2729

2830
function linkInTextBlockEvaluate(node) {
31+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2932
if (isBlock(node)) {
3033
return false;
3134
}
@@ -37,29 +40,47 @@ function linkInTextBlockEvaluate(node) {
3740

3841
this.relatedNodes([parentBlock]);
3942

43+
if(options.a11yRule) {
44+
return distinguishableLinkEvaluate(node, parentBlock);
45+
}
46+
4047
// TODO: Check the :visited state of the link
4148
if (elementIsDistinct(node, parentBlock)) {
4249
return true;
4350
} else {
44-
// Check if contrast of foreground is sufficient
45-
var nodeColor, parentColor;
46-
nodeColor = getForegroundColor(node);
47-
parentColor = getForegroundColor(parentBlock);
51+
// TODO: We should check the focus / hover style too
52+
return checkContrast(node, parentBlock);
53+
}
54+
}
4855

49-
if (!nodeColor || !parentColor) {
50-
return undefined;
51-
}
56+
function getColorContrast(node, parentBlock) {
57+
// Check if contrast of foreground is sufficient
58+
var nodeColor, parentColor;
59+
nodeColor = getForegroundColor(node);
60+
parentColor = getForegroundColor(parentBlock);
5261

53-
var contrast = getContrast(nodeColor, parentColor);
54-
if (contrast === 1) {
55-
return true;
56-
} else if (contrast >= 3.0) {
57-
incompleteData.set('fgColor', 'bgContrast');
58-
this.data({
59-
messageKey: incompleteData.get('fgColor')
60-
});
61-
incompleteData.clear();
62-
// User needs to check whether there is a hover and a focus style
62+
if (!nodeColor || !parentColor) {
63+
return undefined;
64+
}
65+
66+
return getContrast(nodeColor, parentColor);
67+
}
68+
69+
function checkContrast(node, parentBlock) {
70+
var contrast = getColorContrast(node, parentBlock);
71+
if (contrast !== undefined) {
72+
if (contrast === 1) {
73+
return true;
74+
} else if (contrast >= 3.0) {
75+
incompleteData.set('fgColor', 'bgContrast');
76+
this.data({
77+
messageKey: incompleteData.get('fgColor')
78+
});
79+
incompleteData.clear();
80+
// User needs to check whether there is a hover and a focus style
81+
return undefined;
82+
}
83+
} else {
6384
return undefined;
6485
}
6586

@@ -85,10 +106,7 @@ function linkInTextBlockEvaluate(node) {
85106
incompleteData.clear();
86107
return undefined;
87108
}
88-
}
89-
90-
// TODO: We should check the focus / hover style too
91-
return false;
92109
}
93110

94111
export default linkInTextBlockEvaluate;
112+
export { getColorContrast, getContrast }

lib/checks/color/link-in-text-block.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"id": "link-in-text-block",
33
"evaluate": "link-in-text-block-evaluate",
4+
"options": {
5+
"a11yRule": false
6+
},
47
"metadata": {
58
"impact": "serious",
69
"messages": {

lib/rules/link-in-text-block.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"description": "Ensure links are distinguished from surrounding text in a way that does not rely on color",
99
"help": "Links must be distinguishable without relying on color"
1010
},
11-
"all": ["link-in-text-block"],
11+
"all": [{
12+
"options": {
13+
"a11yRule": false
14+
}, "id": "link-in-text-block"
15+
}],
1216
"any": [],
1317
"none": []
1418
}

0 commit comments

Comments
 (0)