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

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

Merged
merged 2 commits into from
Dec 15, 2017
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
7 changes: 5 additions & 2 deletions lib/checks/navigation/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const landmarkRoles = aria.getRolesByType('landmark');
// Create a list of nodeNames that have a landmark as an implicit role
const implicitLandmarks = landmarkRoles
.reduce((arr, role) => arr.concat(aria.implicitNodes(role)), [])
.filter(r => r !== null).map(r => r.toUpperCase());
.filter(r => r !== null);

// Check if the current element is the skiplink
function isSkipLink (node) {
Expand All @@ -26,7 +26,10 @@ function isLandmark (node) {
if (node.hasAttribute('role')) {
return landmarkRoles.includes(node.getAttribute('role').toLowerCase());
} else {
return implicitLandmarks.includes(node.nodeName.toUpperCase());
// Check if the node matches any of the CSS selectors of implicit landmarks
return implicitLandmarks.some((implicitSelector) => {
return axe.utils.matchesSelector(node, implicitSelector);
});
}
}

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 @@ lookupTables.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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@
"standard-version": "^4.2.0"
},
"dependencies": {}
}
}
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