Skip to content

Commit

Permalink
feat(aria-dpub-role-fallback): depreacte aria-dpub-role-fallback and …
Browse files Browse the repository at this point in the history
…move into aria-allowed-role (#1899)

* feat(aria-dpub-role-fallback): depreacte aria-dpub-role-fallback and move into aria-allowed-role

* add comment
  • Loading branch information
straker committed Nov 18, 2019
1 parent 8719700 commit 8e25c20
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/rule-descriptions.md
Expand Up @@ -4,7 +4,7 @@
| area-alt | Ensures <area> elements of image maps have alternate text | Critical | cat.text-alternatives, wcag2a, wcag111, section508, section508.22.a | true | true | false |
| aria-allowed-attr | Ensures ARIA attributes are allowed for an element's role | Critical | cat.aria, wcag2a, wcag412 | true | true | false |
| aria-allowed-role | Ensures role attribute has an appropriate value for the element | Minor | cat.aria, best-practice | true | true | true |
| aria-dpub-role-fallback | Ensures unsupported DPUB roles are only used on elements with implicit fallback roles | Moderate | cat.aria, wcag2a, wcag131 | true | true | false |
| aria-dpub-role-fallback | Ensures unsupported DPUB roles are only used on elements with implicit fallback roles | Moderate | cat.aria, wcag2a, wcag131, deprecated | false | true | false |
| aria-hidden-body | Ensures aria-hidden='true' is not present on the document body. | Critical | cat.aria, wcag2a, wcag412 | true | true | false |
| aria-hidden-focus | Ensures aria-hidden elements do not contain focusable elements | Serious | cat.name-role-value, wcag2a, wcag412, wcag131 | true | true | false |
| aria-input-field-name | Ensures every ARIA input field has an accessible name | Moderate, Serious | wcag2a, wcag412 | true | true | true |
Expand Down
1 change: 1 addition & 0 deletions lib/checks/aria/implicit-role-fallback.json
@@ -1,6 +1,7 @@
{
"id": "implicit-role-fallback",
"evaluate": "implicit-role-fallback.js",
"deprecated": true,
"metadata": {
"impact": "moderate",
"messages": {
Expand Down
21 changes: 21 additions & 0 deletions lib/commons/aria/get-element-unallowed-roles.js
@@ -1,5 +1,17 @@
/* global aria */

// dpub roles which are subclassing roles that are implicit on some native
// HTML elements (img, link, etc.)
const dpubRoles = [
'doc-backlink',
'doc-biblioentry',
'doc-biblioref',
'doc-cover',
'doc-endnote',
'doc-glossref',
'doc-noteref'
];

/**
* Returns all roles applicable to element in a list
*
Expand Down Expand Up @@ -71,6 +83,15 @@ aria.getElementUnallowedRoles = function getElementUnallowedRoles(
return false;
}

// if role is a dpub role make sure it's used on an element with a valid
// implicit role fallback
if (allowImplicit && dpubRoles.includes(role)) {
const roleType = axe.commons.aria.getRoleType(role);
if (implicitRole !== roleType) {
return true;
}
}

// Edge case:
// setting implicit role row on tr element is allowed when child of table[role='grid']
if (
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/aria-dpub-role-fallback.json
Expand Up @@ -2,11 +2,12 @@
"id": "aria-dpub-role-fallback",
"selector": "[role]",
"matches": "aria-dpub-role-fallback-matches.js",
"tags": ["cat.aria", "wcag2a", "wcag131"],
"tags": ["cat.aria", "wcag2a", "wcag131", "deprecated"],
"metadata": {
"description": "Ensures unsupported DPUB roles are only used on elements with implicit fallback roles",
"help": "Unsupported DPUB ARIA roles should be used on elements with implicit fallback roles"
},
"enabled": false,
"all": ["implicit-role-fallback"],
"any": [],
"none": []
Expand Down
16 changes: 16 additions & 0 deletions test/checks/aria/aria-allowed-role.js
Expand Up @@ -299,4 +299,20 @@ describe('aria-allowed-role', function() {
assert.isTrue(actual);
assert.isNull(checkContext._data, null);
});

it('returns false if a dpub role’s type is not the element’s implicit role', function() {
fixture.innerHTML = '<article role="doc-biblioref" id="target"></article>';
var target = fixture.children[0];
assert.isFalse(
checks['aria-allowed-role'].evaluate.call(checkContext, target)
);
});

it('returns true if a dpub role’s type is the element’s implicit role', function() {
fixture.innerHTML = '<a href="foo" role="doc-biblioref" id="target"></a>';
var target = fixture.children[0];
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, target)
);
});
});
25 changes: 25 additions & 0 deletions test/integration/rules/aria-allowed-role/aria-allowed-role.html
Expand Up @@ -135,6 +135,21 @@ <h1 id="pass-h1-valid-role" role="none"></h1>
id="pass-custom-element-any-role"
role="navigation"
></my-custom-element>
<!-- links -->
<a id="pass-dpub-1" role="doc-backlink" href="#">ok</a>
<a id="pass-dpub-2" role="doc-biblioref" href="#">ok</a>
<a id="pass-dpub-3" role="doc-glossref" href="#">ok</a>
<a id="pass-dpub-4" role="doc-noteref" href="#">ok</a>
<!-- images -->
<img id="pass-dpub-5" role="doc-cover" />
<!-- listitems -->
<ul>
<li id="pass-dpub-6" role="doc-biblioentry">ok</li>
</ul>
<ul>
<li id="pass-dpub-7" role="doc-endnote">ok</li>
</ul>

<dd id="fail-dd-no-role" role="link"></dd>
<dt id="fail-dt-no-role" role="banner"></dt>
<label id="fail-label-no-role" role="presentation"></label>
Expand Down Expand Up @@ -167,3 +182,13 @@ <h1 id="pass-h1-valid-role" role="none"></h1>
aria-hidden="true"
role="presentation"
></button>
<!-- links -->
<div id="fail-dpub-1" role="doc-backlink">ok</div>
<div id="fail-dpub-2" role="doc-biblioref">ok</div>
<div id="fail-dpub-3" role="doc-glossref">ok</div>
<div id="fail-dpub-4" role="doc-noteref">ok</div>
<!-- images -->
<div id="fail-dpub-5" role="doc-cover">ok</div>
<!-- listitems -->
<div id="fail-dpub-6" role="doc-biblioentry">ok</div>
<div id="fail-dpub-7" role="doc-endnote">ok</div>
18 changes: 16 additions & 2 deletions test/integration/rules/aria-allowed-role/aria-allowed-role.json
Expand Up @@ -55,7 +55,14 @@
["#pass-ul-role-presentation"],
["#pass-ol-role-none"],
["#pass-ol-role-presentation"],
["#pass-custom-element-any-role"]
["#pass-custom-element-any-role"],
["#pass-dpub-1"],
["#pass-dpub-2"],
["#pass-dpub-3"],
["#pass-dpub-4"],
["#pass-dpub-5"],
["#pass-dpub-6"],
["#pass-dpub-7"]
],
"violations": [
["#fail-dd-no-role"],
Expand All @@ -70,7 +77,14 @@
["#fail-aside-doc-foreword"],
["#fail-aside-role-tab"],
["#fail-button-role-gridcell"],
["#fail-input-role-gridcell-multiple-role"]
["#fail-input-role-gridcell-multiple-role"],
["#fail-dpub-1"],
["#fail-dpub-2"],
["#fail-dpub-3"],
["#fail-dpub-4"],
["#fail-dpub-5"],
["#fail-dpub-6"],
["#fail-dpub-7"]
],
"incomplete": [["#incomplete1"], ["#incomplete2"]]
}

0 comments on commit 8e25c20

Please sign in to comment.