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(getElementStack): do not add hidden elements to the stack #1991

Merged
merged 2 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/commons/dom/get-element-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ function createGrid(
// (we don't do this before so we can calculate stacking context
// of parents with 0 width/height)
const rect = vNode.boundingClientRect;
if (rect.width !== 0 && rect.height !== 0) {
if (rect.width !== 0 && rect.height !== 0 && dom.isVisible(node)) {
addNodeToGrid(grid, vNode);
}

Expand Down
14 changes: 14 additions & 0 deletions test/commons/dom/get-element-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ describe('dom.getElementStack', function() {
assert.deepEqual(stack, ['1', 'fixture', 'target', '2']);
});

it('should not add hidden elements', function() {
fixture.innerHTML =
'<main id="1">' +
'<div id="2" style="position: absolute; display: none;">Some text</div>' +
'<div id="3" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);">Some text</div>' +
'<div id="3" style="position: absolute; visibility: hidden">Some text</div>' +
'<span id="target">Hello World</span>' +
'</main>';
axe.testUtils.flatTreeSetup(fixture);
var target = fixture.querySelector('#target');
var stack = mapToIDs(getElementStack(target));
assert.deepEqual(stack, ['target', '1', 'fixture']);
});

(shadowSupported ? it : xit)(
'should sort shadow dom elements correctly',
function() {
Expand Down