Skip to content

Commit

Permalink
fix(rules/region): Treat <section> as a landmark if it has an accessi…
Browse files Browse the repository at this point in the history
…ble name #640 (#642)

* fix(rules/region): Treat <section> as a landmark if it has an accessible name #640

* chore(checks/region): Add clarifying comment
  • Loading branch information
WilcoFiers committed Dec 15, 2017
1 parent 7cb0325 commit 0131458
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
17 changes: 14 additions & 3 deletions lib/checks/navigation/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
var landmarkRoles = axe.commons.aria.getRolesByType('landmark'),
firstLink = node.querySelector('a[href]');

// Create a list of nodeNames that have a landmark as an implicit role
const implicitLandmarks = landmarkRoles
.reduce((arr, role) => arr.concat(axe.commons.aria.implicitNodes(role)), [])
.filter(r => r !== null);

function isSkipLink(n) {
return firstLink &&
axe.commons.dom.isFocusable(axe.commons.dom.getElementByReference(firstLink, 'href')) &&
firstLink === n;
}

function isLandmark(n) {
var role = n.getAttribute('role');
return role && (landmarkRoles.indexOf(role) !== -1);
function isLandmark(node) {
if (node.hasAttribute('role')) {
return landmarkRoles.includes(node.getAttribute('role').toLowerCase());
} else {
// Check if the node matches any of the CSS selectors of implicit landmarks
return implicitLandmarks.some((implicitSelector) => {
return axe.utils.matchesSelector(node, implicitSelector);
});
}
}

function checkRegion(n) {
Expand Down
4 changes: 2 additions & 2 deletions lib/commons/aria/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ lookupTable.role = {
type: 'abstract'
},
'region': {
type: 'structure',
type: 'landmark',
attributes: {
allowed: ['aria-expanded']
},
owned: null,
nameFrom: ['author'],
context: null,
implicit: ['section']
implicit: ['section[aria-label]', 'section[aria-labelledby]', 'section[title]']
},
'roletype': {
type: 'abstract'
Expand Down
3 changes: 3 additions & 0 deletions test/integration/full/region/region-fail.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ <h1 id="mainheader" tabindex="0">This is a header.</h1>
<li>Home</li>
<li>Other</li>
</ul>
<section>
<p>Content</p>
</section>
<div id="mocha"></div>
<script src="region-fail.js"></script>
<script src="/test/integration/adapter.js"></script>
Expand Down
10 changes: 10 additions & 0 deletions test/integration/full/region/region-pass.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ <h1 id="mainheader" tabindex="0">This is a header.</h1>
<li>Home</li>
<li>Other</li>
</ul>
<section aria-labelledby="hdng">
<h1 id="hdng">Section heading</h1>
<p>Content</p>
</section>
<section aria-label="section 2">
<p>Content</p>
</section>
<section title="section 3">
<p>Content</p>
</section>
<div id="mocha" role="complementary"></div>
<script src="region-pass.js"></script>
<script src="/test/integration/adapter.js"></script>
Expand Down

0 comments on commit 0131458

Please sign in to comment.