Skip to content

Commit

Permalink
fix(page-no-duplicate): don't count elements hidden from screenreader…
Browse files Browse the repository at this point in the history
…s as potential duplicates (#3051)
  • Loading branch information
clottman authored Jun 29, 2021
1 parent e93fdb1 commit 5e0098b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checks/generic/page-no-duplicate-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function pageNoDuplicateEvaluate(node, options, virtualNode) {
cache.set(key, true);

let elms = querySelectorAllFilter(axe._tree[0], options.selector, elm =>
isVisible(elm.actualNode)
isVisible(elm.actualNode, true)
);

// Filter elements that, within certain contexts, don't map their role.
Expand Down
33 changes: 33 additions & 0 deletions test/checks/keyboard/page-no-duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe('page-no-duplicate', function() {
assert.isTrue(check.evaluate.apply(checkContext, params));
});

it('should return true if there is more than one element matching the selector but only one is visible to screenreaders', function() {
var options = { selector: 'main' };
var params = checkSetup(
'<div><main id="target" aria-hidden="true"></main><main id="dup"></main></div>',
options
);
assert.isTrue(check.evaluate.apply(checkContext, params));
});

(shadowSupported ? it : xit)(
'should return false if there is a second matching element inside the shadow dom',
function() {
Expand All @@ -81,6 +90,30 @@ describe('page-no-duplicate', function() {
]);
}
);

(shadowSupported ? it : xit)(
'should return true if there is a second matching element inside the shadow dom but only one is visible to screenreaders',
function() {
var options = { selector: 'main' };
var div = document.createElement('div');
div.innerHTML =
'<div id="shadow"></div><main id="target" aria-hidden="true"></main>';

var shadow = div
.querySelector('#shadow')
.attachShadow({ mode: 'open' });
shadow.innerHTML = '<main></main>';
axe.testUtils.fixtureSetup(div);
var vNode = axe.utils.querySelectorAll(axe._tree, '#target')[0];

assert.isTrue(
check.evaluate.call(checkContext, vNode.actualNode, options, vNode)
);
assert.deepEqual(checkContext._relatedNodes, [
shadow.querySelector('main')
]);
}
);
});

describe('option.nativeScopeFilter', function() {
Expand Down

0 comments on commit 5e0098b

Please sign in to comment.