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 live-region and dialog in region rule #1073

Merged
merged 3 commits into from
Aug 21, 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
45 changes: 25 additions & 20 deletions lib/checks/navigation/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,32 @@ function isSkipLink(vNode) {
}

// Check if the current element is a landmark
function isLandmark(virtualNode) {
var node = virtualNode.actualNode;
var explictRole = (node.getAttribute('role') || '').trim().toLowerCase();
function isRegion(virtualNode) {
const node = virtualNode.actualNode;
const explicitRole = axe.commons.aria.getRole(node, { noImplicit: true });
const ariaLive = (node.getAttribute('aria-live') || '').toLowerCase().trim();

if (explictRole) {
return landmarkRoles.includes(explictRole);
} else {
// Check if the node matches any of the CSS selectors of implicit landmarks
return implicitLandmarks.some(implicitSelector => {
let matches = axe.utils.matchesSelector(node, implicitSelector);
if (node.tagName.toLowerCase() === 'form') {
let titleAttr = node.getAttribute('title');
let title =
titleAttr && titleAttr.trim() !== ''
? axe.commons.text.sanitize(titleAttr)
: null;
return matches && (!!aria.labelVirtual(virtualNode) || !!title);
}
return matches;
});
if (explicitRole) {
return explicitRole === 'dialog' || landmarkRoles.includes(explicitRole);
}
// Ignore content inside of aria-live
if (['assertive', 'polite'].includes(ariaLive)) {
return true;
}

// Check if the node matches any of the CSS selectors of implicit landmarks
return implicitLandmarks.some(implicitSelector => {
let matches = axe.utils.matchesSelector(node, implicitSelector);
if (node.tagName.toLowerCase() === 'form') {
let titleAttr = node.getAttribute('title');
let title =
titleAttr && titleAttr.trim() !== ''
? axe.commons.text.sanitize(titleAttr)
: null;
return matches && (!!aria.labelVirtual(virtualNode) || !!title);
}
return matches;
});
}

/**
Expand All @@ -55,7 +60,7 @@ function findRegionlessElms(virtualNode) {
const node = virtualNode.actualNode;
// End recursion if the element is a landmark, skiplink, or hidden content
if (
isLandmark(virtualNode) ||
isRegion(virtualNode) ||
isSkipLink(virtualNode) ||
!dom.isVisible(node, true)
) {
Expand Down
29 changes: 29 additions & 0 deletions test/checks/navigation/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,35 @@ describe('region', function() {
assert.isTrue(checks.region.evaluate.apply(checkContext, checkArgs));
});

it('allows content in aria-live=assertive', function() {
var checkArgs = checkSetup(
'<div aria-live="assertive" id="target"><p>This is random content.</p></div>'
);
assert.isTrue(checks.region.evaluate.apply(checkContext, checkArgs));
});

it('allows content in aria-live=polite', function() {
var checkArgs = checkSetup(
'<div aria-live="polite" id="target"><p>This is random content.</p></div>'
);
assert.isTrue(checks.region.evaluate.apply(checkContext, checkArgs));
});

it('does not allow content in aria-live=off', function() {
var checkArgs = checkSetup(
'<div aria-live="off" id="target"><p>This is random content.</p></div>'
);
assert.isFalse(checks.region.evaluate.apply(checkContext, checkArgs));
});

it('treats role=dialog elements as regions', function() {
var checkArgs = checkSetup(
'<div role="dialog" id="target"><p>This is random content.</p></div>'
);

assert.isTrue(checks.region.evaluate.apply(checkContext, checkArgs));
});

(shadowSupport.v1 ? it : xit)('should test Shadow tree content', function() {
var div = document.createElement('div');
var shadow = div.attachShadow({ mode: 'open' });
Expand Down