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(role-text): add role-text rule #2702

Merged
merged 4 commits into from
Jan 11, 2021
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 @@ -82,6 +82,7 @@ Rules that do not necessarily conform to WCAG success criterion but are industry
| [accesskeys](https://dequeuniversity.com/rules/axe/4.1/accesskeys?application=RuleDescription) | Ensures every accesskey attribute value is unique | Serious | cat.keyboard, best-practice | failure |
| [aria-allowed-role](https://dequeuniversity.com/rules/axe/4.1/aria-allowed-role?application=RuleDescription) | Ensures role attribute has an appropriate value for the element | Minor | cat.aria, best-practice | failure, needs review |
| [aria-dialog-name](https://dequeuniversity.com/rules/axe/4.1/aria-dialog-name?application=RuleDescription) | Ensures every ARIA dialog and alertdialog node has an accessible name | Serious | cat.aria, best-practice | failure, needs review |
| [aria-text](https://dequeuniversity.com/rules/axe/4.1/aria-text?application=RuleDescription) | Ensures "role=text" is used correctly | Serious | cat.aria, best-practice | failure, needs review |
| [aria-treeitem-name](https://dequeuniversity.com/rules/axe/4.1/aria-treeitem-name?application=RuleDescription) | Ensures every ARIA treeitem node has an accessible name | Serious | cat.aria, best-practice | failure, needs review |
| [empty-heading](https://dequeuniversity.com/rules/axe/4.1/empty-heading?application=RuleDescription) | Ensures headings have discernible text | Minor | cat.name-role-value, best-practice | failure, needs review |
| [frame-tested](https://dequeuniversity.com/rules/axe/4.1/frame-tested?application=RuleDescription) | Ensures <iframe> and <frame> elements contain the axe-core script | Critical | cat.structure, review-item, best-practice | failure, needs review |
Expand Down
12 changes: 12 additions & 0 deletions lib/rules/aria-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "aria-text",
"selector": "[role=text]",
"tags": ["cat.aria", "best-practice"],
"metadata": {
"description": "Ensures \"role=text\" is used on elements with no focusable descendants",
"help": "\"role=text\" should have no focusable descendants"
},
"all": [],
"any": ["no-focusable-content"],
"none": []
}
5 changes: 5 additions & 0 deletions lib/standards/aria-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ const ariaRoles = {
// Note: spec difference
nameFromContent: true
},
text: {
type: 'structure',
superclassRole: ['section'],
nameFromContent: true
},
textbox: {
type: 'widget',
allowedAttrs: [
Expand Down
1 change: 1 addition & 0 deletions test/commons/standards/get-aria-roles-by-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('standards.getAriaRolesByType', function() {
'superscript',
'table',
'term',
'text',
'time',
'toolbar',
'tooltip'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('standards.getAriaRolesSupportingNameFromContent', function() {
'tab',
'table',
'term',
'text',
'tooltip',
'treeitem',
'doc-backlink',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ <h1 id="pass-h1-valid-role" role="none"></h1>
</ul>
<hr id="hr-presentation" role="presentation" />
<hr id="hr-none" role="none" />
<span role="text" id="span-text" />
<div role="text" id="div-text" />
<p role="text" id="p-text" />

<dd id="fail-dd-no-role" role="link"></dd>
<dt id="fail-dt-no-role" role="banner"></dt>
Expand Down Expand Up @@ -212,3 +215,7 @@ <h1 id="pass-h1-valid-role" role="none"></h1>
<!-- listitems -->
<div id="fail-dpub-6" role="doc-biblioentry">ok</div>
<div id="fail-dpub-7" role="doc-endnote">ok</div>
<h1 role="text" id="fail-text-1">ok</h1>
<button role="text" id="fail-text-2">ok</button>
<a href="#" role="text" id="fail-text-3">ok</a>
<main role="text" id="fail-text-4">ok</main>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
["#pass-dpub-6"],
["#pass-dpub-7"],
["#hr-presentation"],
["#hr-none"]
["#hr-none"],
["#span-text"],
["#div-text"],
["#p-text"]
],
"violations": [
["#fail-dd-no-role"],
Expand All @@ -88,7 +91,11 @@
["#fail-dpub-4"],
["#fail-dpub-5"],
["#fail-dpub-6"],
["#fail-dpub-7"]
["#fail-dpub-7"],
["#fail-text-1"],
["#fail-text-2"],
["#fail-text-3"],
["#fail-text-4"]
],
"incomplete": [["#incomplete1"], ["#incomplete2"]]
}
4 changes: 2 additions & 2 deletions test/integration/rules/aria-roles/aria-roles.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<div role="doc-tip" id="pass107">ok</div>
<div role="doc-toc" id="pass108">ok</div>
<div role="figure" id="pass109">ok</div>
<div role="text" id="pass110">ok</div>
</div>
<div id="violation">
<!-- abstract roles -->
Expand All @@ -124,10 +125,9 @@
<div role="window" id="fail12">fail</div>
<!-- invalid roles -->
<div role="lol" id="fail13">fail</div>
<div role="text" id="fail14">ok</div>
<!-- unsupported roles -->
<!-- fallback roles -->
<div role="button alert" id="fail15">fail</div>
<div role="button alert" id="fail14">fail</div>
</div>

<!-- inapplicable -->
Expand Down
6 changes: 3 additions & 3 deletions test/integration/rules/aria-roles/aria-roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
["#fail11"],
["#fail12"],
["#fail13"],
["#fail14"],
["#fail15"]
["#fail14"]
],
"passes": [
["#pass1"],
Expand Down Expand Up @@ -126,6 +125,7 @@
["#pass106"],
["#pass107"],
["#pass108"],
["#pass109"]
["#pass109"],
["#pass110"]
]
}
22 changes: 22 additions & 0 deletions test/integration/rules/aria-text/aria-text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h1>
<span role="text" id="pass1"
>Digital accessibility, <br />
for everyone.
</span>
</h1>
<a href="#"
><span role="text" id="pass2">Buy <strong>t-shirts</strong> now</span></a
>
<div role="text" id="pass3">Some text<span> and some more text</span></div>

<div role="text" id="fail1">
Still an <a href="#">interactive link</a> because of the author error.
</div>
<div role="text" id="fail2">
<a href="#" role="none">Flattened text</a> because of the explicit role.
</div>
<div role="text" id="fail3">
<a href="#" tabindex="-1" role="none">Flattened text</a> because of the
explicit role.
</div>
<p role="text" id="fail4"><button>Hello</button></p>
6 changes: 6 additions & 0 deletions test/integration/rules/aria-text/aria-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "aria-text tests",
"rule": "aria-text",
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"]],
"passes": [["#pass1"], ["#pass2"], ["#pass3"]]
}