Skip to content

Commit

Permalink
fix: allow list items as children of roles inheriting from 'list'
Browse files Browse the repository at this point in the history
Fixes #239
  • Loading branch information
rdeltour committed Jul 8, 2019
1 parent 6cb5402 commit a362050
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ace-core/src/checker/checker-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const scripts = [
require.resolve('../scripts/axe-patch-aria-roles.js'),
require.resolve('../scripts/axe-patch-is-aria-role-allowed.js'),
require.resolve('../scripts/axe-patch-only-list-items.js'),
require.resolve('../scripts/axe-patch-listitem.js'),
require.resolve('../scripts/ace-axe.js'),
require.resolve('../scripts/ace-extraction.js'),
];
Expand Down
32 changes: 32 additions & 0 deletions packages/ace-core/src/scripts/axe-patch-listitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

/*
This patch is needed to ensure that roles *inheriting* a list role are allowed
as listitem parents.
E.g. `<ul role="directory">` as parent of `li`.
*/

(function axePatch(window) {
const axe = window.axe;

axe._audit.checks['listitem'].evaluate = function evaluate(node, options, virtualNode, context) {
const parent = axe.commons.dom.getComposedParent(node);
if (!parent) {
// Can only happen with detached DOM nodes and roots:
return undefined;
}

const parentTagName = parent.nodeName.toUpperCase();
const parentRole = (parent.getAttribute('role') || '').toLowerCase();

if (parentRole === 'list') {
return true;
}

if (parentRole && axe.commons.aria.isValidRole(parentRole)) {
return aria.getRoleType(role) === 'list';
}

return ['UL', 'OL'].includes(parentTagName);
}
}(window));
5 changes: 5 additions & 0 deletions tests/__tests__/regression.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ test('issue #209: `aria-describedby` can be a list of IDs', async () => {
])
}));
});

test('issue #239: `listitem` is not reported when roles inherit from list roles', async () => {
const report = await ace('../data/issue-239');
expect(report['earl:result']['earl:outcome']).toEqual('pass');
});
19 changes: 19 additions & 0 deletions tests/data/issue-239/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<nav>
<h1>Contents</h1>
<ol role="directory">
<li><a href="preface_001.xhtml">Original Transcriber’s Notes:</a></li>
<li><a href="introduction_001.xhtml">ETYMOLOGY.</a></li>
<li><a href="epigraph_001.xhtml">EXTRACTS (Supplied by a Sub-Sub-Librarian).</a></li>
<li><a href="chapter_001.xhtml">Chapter 1. Loomings.</a></li>
</ol>
</nav>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/issue-239/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
23 changes: 23 additions & 0 deletions tests/data/issue-239/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
6 changes: 6 additions & 0 deletions tests/data/issue-239/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/issue-239/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit a362050

Please sign in to comment.