Skip to content

Commit

Permalink
fix(matches-selector): don't call matches function if none exist on t…
Browse files Browse the repository at this point in the history
…he element (#1613)

* fix(find-up): fix IE11 to not pass document element to matchesSelector

* fix test
  • Loading branch information
straker authored and AutoSponge committed Jun 6, 2019
1 parent 7581592 commit a470b91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ text.accessibleTextVirtual = function accessibleTextVirtual(
aria.arialabelText, // Step 2C
text.nativeTextAlternative, // Step 2D
text.formControlValue, // Step 2E
text.subtreeText, // Step 2F + Step 2H
subtreeText, // Step 2F + Step 2H
textNodeContent, // Step 2G (order with 2H does not matter)
text.titleText // Step 2I
];
Expand Down Expand Up @@ -150,3 +150,13 @@ text.accessibleTextVirtual.alreadyProcessed = function alreadyProcessed(
context.processed.push(virtualnode);
return false;
};

function subtreeText(virtualnode, context = {}) {
const hasNoInterestingText = !(virtualnode.children || [])
.filter(vchild => vchild.actualNode.nodeType === Node.TEXT_NODE)
.filter(vtextNode => vtextNode.actualNode.textContent.trim().length).length;
if (hasNoInterestingText) {
return '';
}
return text.subtreeText(virtualnode, context);
}
12 changes: 12 additions & 0 deletions test/commons/text/accessible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,18 @@ describe('text.accessibleTextVirtual', function() {
assert.equal(accessibleText(target), 'Country of origin: United States');
});

it('ignores genericContainers with no interesting textNodes', function() {
fixture.innerHTML =
'<div id="test">' +
'<div class="container">' +
'<h1>Something Interesting</h1>' +
'</div>' +
'</div>';
axe.testUtils.flatTreeSetup(fixture);
var target = fixture.querySelector('#test');
assert.equal(accessibleText(target), '');
});

/**
// In case anyone even wants it, here's the script used to generate these test cases
function getTestCase(content, index = 0) {
Expand Down

0 comments on commit a470b91

Please sign in to comment.