Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/1.4.1 - Extended rule link-in-text-block #30

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 39 additions & 21 deletions lib/checks/color/link-in-text-block-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
incompleteData
} from '../../commons/color';

import a11y_engine_commons from '../../commons/a11y-engine-index';

function getContrast(color1, color2) {
var c1lum = color1.getRelativeLuminance();
var c2lum = color2.getRelativeLuminance();
Expand All @@ -26,6 +28,7 @@ function isBlock(elm) {
}

function linkInTextBlockEvaluate(node) {
var options = arguments.length > 1 && arguments[1] ? arguments[1] : {};
Pooja0504 marked this conversation as resolved.
Show resolved Hide resolved
if (isBlock(node)) {
return false;
}
Expand All @@ -37,29 +40,47 @@ function linkInTextBlockEvaluate(node) {

this.relatedNodes([parentBlock]);

if(options.a11yRule) {
return a11y_engine_commons.distinguishableLinkEvaluate(node, parentBlock);
}

// TODO: Check the :visited state of the link
if (elementIsDistinct(node, parentBlock)) {
return true;
} else {
// Check if contrast of foreground is sufficient
var nodeColor, parentColor;
nodeColor = getForegroundColor(node);
parentColor = getForegroundColor(parentBlock);
// TODO: We should check the focus / hover style too
return checkContrast(node, parentBlock);
}
}

if (!nodeColor || !parentColor) {
return undefined;
}
function getColorContrast(node, parentBlock) {
// Check if contrast of foreground is sufficient
var nodeColor, parentColor;
nodeColor = getForegroundColor(node);
parentColor = getForegroundColor(parentBlock);

var contrast = getContrast(nodeColor, parentColor);
if (contrast === 1) {
return true;
} else if (contrast >= 3.0) {
incompleteData.set('fgColor', 'bgContrast');
this.data({
messageKey: incompleteData.get('fgColor')
});
incompleteData.clear();
// User needs to check whether there is a hover and a focus style
if (!nodeColor || !parentColor) {
return undefined;
}

return getContrast(nodeColor, parentColor);
}

function checkContrast(node, parentBlock) {
var contrast = getColorContrast(node, parentBlock);
if (contrast !== undefined) {
if (contrast === 1) {
return true;
} else if (contrast >= 3.0) {
incompleteData.set('fgColor', 'bgContrast');
this.data({
messageKey: incompleteData.get('fgColor')
});
incompleteData.clear();
// User needs to check whether there is a hover and a focus style
return undefined;
}
} else {
return undefined;
}

Expand All @@ -85,10 +106,7 @@ function linkInTextBlockEvaluate(node) {
incompleteData.clear();
return undefined;
}
}

// TODO: We should check the focus / hover style too
return false;
}

export default linkInTextBlockEvaluate;
export { getColorContrast, getContrast }
Pooja0504 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions lib/checks/color/link-in-text-block.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"id": "link-in-text-block",
"evaluate": "link-in-text-block-evaluate",
"options": {
"a11yRule": false
},
"metadata": {
"impact": "serious",
"messages": {
Expand Down
6 changes: 6 additions & 0 deletions lib/commons/a11y-engine-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { distinguishableLinkEvaluate } from '../../../a11y-engine-core/lib/commons/distinguishable-link';

let a11y_engine_commons = {};
a11y_engine_commons.distinguishableLinkEvaluate = distinguishableLinkEvaluate;

export default a11y_engine_commons;
6 changes: 5 additions & 1 deletion lib/rules/link-in-text-block.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"description": "Ensure links are distinguished from surrounding text in a way that does not rely on color",
"help": "Links must be distinguishable without relying on color"
},
"all": ["link-in-text-block"],
"all": [{
"options": {
"a11yRule": false
}, "id": "link-in-text-block"
}],
"any": [],
"none": []
}