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-tooltip-name, check that tooltips have an accessible name #2548

Merged
merged 1 commit into from
Oct 13, 2020
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
1 change: 1 addition & 0 deletions doc/rule-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| [aria-roledescription](https://dequeuniversity.com/rules/axe/4.0/aria-roledescription?application=RuleDescription) | Ensure aria-roledescription is only used on elements with an implicit or explicit role | Serious | cat.aria, wcag2a, wcag412 | failure, needs review |
| [aria-roles](https://dequeuniversity.com/rules/axe/4.0/aria-roles?application=RuleDescription) | Ensures all elements with a role attribute use a valid value | Serious, Critical | cat.aria, wcag2a, wcag412 | failure |
| [aria-toggle-field-name](https://dequeuniversity.com/rules/axe/4.0/aria-toggle-field-name?application=RuleDescription) | Ensures every ARIA toggle field has an accessible name | Moderate, Serious | wcag2a, wcag412 | failure, needs review |
| [aria-tooltip-name](https://dequeuniversity.com/rules/axe/4.0/aria-tooltip-name?application=RuleDescription) | Ensures every ARIA tooltip node has an accessible name | Serious | wcag2a, wcag412 | failure, needs review |
| [aria-valid-attr-value](https://dequeuniversity.com/rules/axe/4.0/aria-valid-attr-value?application=RuleDescription) | Ensures all ARIA attributes have valid values | Critical | cat.aria, wcag2a, wcag412 | failure, needs review |
| [aria-valid-attr](https://dequeuniversity.com/rules/axe/4.0/aria-valid-attr?application=RuleDescription) | Ensures attributes that begin with aria- are valid ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | failure |
| [audio-caption](https://dequeuniversity.com/rules/axe/4.0/audio-caption?application=RuleDescription) | Ensures <audio> elements have captions | Critical | cat.time-and-media, wcag2a, wcag121, section508, section508.22.a | needs review |
Expand Down
10 changes: 9 additions & 1 deletion lib/rules/aria-form-field-name-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ function ariaFormFieldNameMatches(node, virtualNode) {
*/
const nodeName = virtualNode.props.nodeName;
const role = getExplicitRole(virtualNode);
const hasHrefAttr = !!virtualNode.attr('href');

/**
* Ignore elements from rule -> 'link-name'
*/
if (nodeName === 'a' && hasHrefAttr) {
WilcoFiers marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

/**
* Ignore elements from rule -> 'area-alt'
*/
if (nodeName === 'area' && !!virtualNode.attr('href')) {
if (nodeName === 'area' && hasHrefAttr) {
return false;
}

Expand Down
18 changes: 18 additions & 0 deletions lib/rules/aria-tooltip-name.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "aria-tooltip-name",
"selector": "[role=\"tooltip\"]",
"matches": "aria-form-field-name-matches",
"tags": ["wcag2a", "wcag412"],
"metadata": {
"description": "Ensures every ARIA tooltip node has an accessible name",
"help": "ARIA tooltip ndoes must have an accessible name"
},
"all": [],
"any": [
"aria-label",
"aria-labelledby",
"non-empty-title",
"has-visible-text"
],
"none": []
}
26 changes: 26 additions & 0 deletions test/integration/rules/aria-tooltip-name/aria-tooltip-name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- PASS -->
<div id="pass1" role="tooltip">Copy this content</div>
<div id="pass2" role="tooltip" title="Copy this content"></div>
<div id="pass3" role="tooltip" aria-label="Copy this content"></div>
<div id="pass4" role="tooltip" aria-labelledby="copy"></div>

<div id="copy">Copy this content</div>

<!-- FAIL -->
<div id="fail1" role="tooltip"></div>
<div id="fail2" role="tooltip" aria-labelledby="copy-non-existant"></div>
<div id="fail3" role="tooltip" aria-labelledby="copy-empty"></div>

<div id="copy-empty"></div>

<!-- INAPPLICABLE -->
<img role="tooltip" alt="Label" id="inapplicable1" />
<input role="tooltip" title="Label" id="inapplicable2" />
<button role="tooltip" title="Label" id="inapplicable3"></button>
<a href="#" role="tooltip" title="Label" id="inapplicable4"></a>
<select role="tooltip" title="Label" id="inapplicable5">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
</select>
<textarea role="tooltip" id="inapplicable6" title="Label"></textarea>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "aria-tooltip-name test",
"rule": "aria-tooltip-name",
"passes": [["#pass1"], ["#pass2"], ["#pass3"], ["#pass4"]],
"violations": [["#fail1"], ["#fail2"], ["#fail3"]]
}
89 changes: 89 additions & 0 deletions test/integration/virtual-rules/aria-tooltip-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
describe('aria-tooltip-name', function() {
it('should pass for aria-label', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'tooltip',
'aria-label': 'foobar'
}
});
node.parent = null;

var results = axe.runVirtualRule('aria-tooltip-name', node);

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

it('should incomplete for aria-labelledby', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'tooltip',
'aria-labelledby': 'foobar'
}
});
node.parent = null;

var results = axe.runVirtualRule('aria-tooltip-name', node);

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

it('should pass for title', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'tooltip',
title: 'foobar'
}
});
// children are required since titleText comes after subtree text
// in accessible name calculation
node.children = [];
node.parent = null;

var results = axe.runVirtualRule('aria-tooltip-name', node);

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

it('should fail when aria-label contains only whitespace', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'tooltip',
'aria-label': ' \t \n '
}
});
node.children = [];

var results = axe.runVirtualRule('aria-tooltip-name', node);

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

it('should fail when title is empty', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'tooltip',
title: ''
}
});
node.children = [];

var results = axe.runVirtualRule('aria-tooltip-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});
});
6 changes: 6 additions & 0 deletions test/rule-matches/aria-form-field-name-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ describe('aria-form-field-name-matches', function() {
fixture.innerHTML = '';
});

it('returns false for node `a[href]`', function() {
var vNode = queryFixture('<a href="# role="checkbox" id="target"></a>');
var actual = rule.matches(null, vNode);
assert.isFalse(actual);
});

it('returns false for node `map area[href]`', function() {
var vNode = queryFixture(
'<map><area id="target" href="#" role="checkbox"></map>'
Expand Down