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: Allow divs as groups in dl #1076

Merged
merged 2 commits into from
Aug 22, 2018
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
21 changes: 17 additions & 4 deletions lib/checks/lists/only-dlitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@ const ALLOWED_TAGS = [
];

const ALLOWED_ROLES = ['definition', 'term', 'list'];
const { getRole } = axe.commons.aria;

let base = {
badNodes: [],
hasNonEmptyTextNode: false
};

const result = virtualNode.children.reduce((out, childNode) => {
const content = virtualNode.children.reduce((content, child) => {
const { actualNode } = child;
if (
actualNode.nodeName.toUpperCase() === 'DIV' &&
getRole(actualNode) === null
) {
return content.concat(child.children);
}
return content.concat(child);
}, []);

const result = content.reduce((out, childNode) => {
const { actualNode } = childNode;
const tagName = actualNode.nodeName.toUpperCase();

if (actualNode.nodeType === 1 && !ALLOWED_TAGS.includes(tagName)) {
const role = (actualNode.getAttribute('role') || '').toLowerCase();
if ((tagName !== 'DT' && tagName !== 'DD') || role) {
if (!ALLOWED_ROLES.includes(role)) {
const explicitRole = getRole(actualNode, { noImplicit: true });

if ((tagName !== 'DT' && tagName !== 'DD') || explicitRole) {
if (!ALLOWED_ROLES.includes(explicitRole)) {
// handle comment - https://github.com/dequelabs/axe-core/pull/518/files#r139284668
out.badNodes.push(actualNode);
}
Expand Down
18 changes: 18 additions & 0 deletions test/checks/lists/only-dlitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ describe('only-dlitems', function() {
);
});

it('should return false if the list has dt and dd inside a div group', function() {
var checkArgs = checkSetup(
'<dl id="target"><div><dt>An item</dt><dd>A list</dd></div></dl>'
);
assert.isFalse(
checks['only-dlitems'].evaluate.apply(checkContext, checkArgs)
);
});

it('should return true if the list has dt and dd inside a div group with a role', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a test with other content inside the div?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolving in a new PR

var checkArgs = checkSetup(
'<dl id="target"><div role="listitem"><dt>An item</dt><dd>A list</dd></div></dl>'
);
assert.isTrue(
checks['only-dlitems'].evaluate.apply(checkContext, checkArgs)
);
});

(shadowSupport.v1 ? it : xit)(
'should return false in a shadow DOM pass',
function() {
Expand Down