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

feat(new-rule): aria-braille-equivalent finds incorrect uses of aria-braille attributes #4107

Merged
merged 5 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Resolve feedback
  • Loading branch information
WilcoFiers committed Jul 31, 2023
commit c839ea69d0cee760c54685f4ca117d2b0ef88688
2 changes: 1 addition & 1 deletion doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| :------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------- | :--------------------------------------------------------------------------------------------------------------------------------- | :------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [area-alt](https://dequeuniversity.com/rules/axe/4.7/area-alt?application=RuleDescription) | Ensures <area> elements of image maps have alternate text | Critical | cat.text-alternatives, wcag2a, wcag244, wcag412, section508, section508.22.a, TTv5, TT6.a, EN-301-549, EN-9.2.4.4, EN-9.4.1.2, ACT | failure, needs review | [c487ae](https://act-rules.github.io/rules/c487ae) |
| [aria-allowed-attr](https://dequeuniversity.com/rules/axe/4.7/aria-allowed-attr?application=RuleDescription) | Ensures an element's role supports its ARIA attributes | Serious, Critical | cat.aria, wcag2a, wcag412, EN-301-549, EN-9.4.1.2 | failure, needs review | [5c01ea](https://act-rules.github.io/rules/5c01ea) |
| [aria-braille-equivalent](https://dequeuniversity.com/rules/axe/4.7/aria-braille-equivalent?application=RuleDescription) | Ensure aria-braillelabel and aria-brailleroledescription have a non-braille equivalent | Serious | cat.aria, wcag2a, wcag412, EN-301-549, EN-9.4.1.2 | failure | |
| [aria-braille-equivalent](https://dequeuniversity.com/rules/axe/4.7/aria-braille-equivalent?application=RuleDescription) | Ensure aria-braillelabel and aria-brailleroledescription have a non-braille equivalent | Serious | cat.aria, wcag2a, wcag412, EN-301-549, EN-9.4.1.2 | failure, needs review | |
| [aria-command-name](https://dequeuniversity.com/rules/axe/4.7/aria-command-name?application=RuleDescription) | Ensures every ARIA button, link and menuitem has an accessible name | Serious | cat.aria, wcag2a, wcag412, TTv5, TT6.a, EN-301-549, EN-9.4.1.2, ACT | failure, needs review | [97a4e1](https://act-rules.github.io/rules/97a4e1) |
| [aria-deprecated-role](https://dequeuniversity.com/rules/axe/4.7/aria-deprecated-role?application=RuleDescription) | Ensures elements do not use deprecated roles | Minor | cat.aria, wcag2a, wcag412, EN-301-549, EN-9.4.1.2 | failure | [674b10](https://act-rules.github.io/rules/674b10) |
| [aria-hidden-body](https://dequeuniversity.com/rules/axe/4.7/aria-hidden-body?application=RuleDescription) | Ensures aria-hidden='true' is not present on the document body. | Critical | cat.aria, wcag2a, wcag412, EN-301-549, EN-9.4.1.2 | failure | |
Expand Down
8 changes: 6 additions & 2 deletions lib/checks/aria/braille-label-equivalent-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { accessibleTextVirtual } from '../../commons/text';
import { sanitize, accessibleTextVirtual } from '../../commons/text';

/**
* Check that if aria-braillelabel is not empty, the element has an accessible text
Expand All @@ -14,5 +14,9 @@ export default function brailleLabelEquivalentEvaluate(
if (!brailleLabel.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use sanitize from our text functions here instead (similar to aria-label and aria-labelledby checks)?

Copy link
Contributor Author

@WilcoFiers WilcoFiers Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't use it for aria-labelledby either. What sanitize does that trim doesn't do is replace duplicate whitespace characters in between words with single space characters. We don't need that here.

Suppose it doesn't matter much though. And if we do ever need to do this in a way that's different from trim it helps to have them in place.

return true;
}
return accessibleTextVirtual(virtualNode) !== '';
try {
return sanitize(accessibleTextVirtual(virtualNode)) !== '';
} catch {
return undefined;
}
}
5 changes: 3 additions & 2 deletions lib/checks/aria/braille-label-equivalent.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"metadata": {
"impact": "serious",
"messages": {
"pass": "aria-braillelabel is not used on an element with no accessible text",
"fail": "aria-braillelabel is used on an element with no accessible text"
"pass": "aria-braillelabel is used on an element with accessible text",
"fail": "aria-braillelabel is used on an element with no accessible text",
"incomplete": "Unable to compute accessible text"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { sanitize } from '../../commons/text';

/**
* Check that if aria-brailleroledescription is not empty,
* the element has a non-empty aria-roledescription
Expand All @@ -10,7 +12,7 @@ export default function brailleRoleDescriptionEquivalentEvaluate(
virtualNode
) {
const brailleRoleDesc = virtualNode.attr('aria-brailleroledescription') ?? '';
if (!brailleRoleDesc.trim()) {
if (sanitize(brailleRoleDesc) === '') {
return true;
}
const roleDesc = virtualNode.attr('aria-roledescription');
Expand All @@ -19,7 +21,7 @@ export default function brailleRoleDescriptionEquivalentEvaluate(
return false;
}

if (roleDesc.trim() === '') {
if (sanitize(roleDesc) === '') {
this.data({ messageKey: 'emptyRoleDescription' });
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions locales/_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,9 @@
}
},
"braille-label-equivalent": {
"pass": "aria-braillelabel is not used on an element with no accessible text",
"fail": "aria-braillelabel is used on an element with no accessible text"
"pass": "aria-braillelabel is used on an element with accessible text",
"fail": "aria-braillelabel is used on an element with no accessible text",
"incomplete": "Unable to compute accessible text"
},
"braille-roledescription-equivalent": {
"pass": "aria-brailleroledescription is not used on an element with no accessible text",
Expand Down
13 changes: 13 additions & 0 deletions test/integration/virtual-rules/aria-braille-equivalent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ describe('aria-braille-equivalent virtual-rule', () => {
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});

it('incompletes if the subtree fails to compute with aria-braillelabel', () => {
const results = axe.runVirtualRule('aria-braille-equivalent', {
nodeName: 'button',
attributes: {
'aria-braillelabel': 'Hello world'
}
});

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 1);
});
});