Skip to content

Commit

Permalink
fix tap target
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Sep 15, 2020
1 parent 7fd0b73 commit d657e76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 7 additions & 6 deletions lighthouse-core/gather/gatherers/seo/tap-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ function getClientRects(element) {

/**
* @param {Element} element
* @param {string} tapTargetsSelector
* @returns {boolean}
*/
/* istanbul ignore next */
function elementHasAncestorTapTarget(element) {
function elementHasAncestorTapTarget(element, tapTargetsSelector) {
if (!element.parentElement) {
return false;
}
if (element.parentElement.matches(tapTargetsSelector)) {
return true;
}
return elementHasAncestorTapTarget(element.parentElement);
return elementHasAncestorTapTarget(element.parentElement, tapTargetsSelector);
}

/**
Expand Down Expand Up @@ -202,10 +203,11 @@ function disableFixedAndStickyElementPointerEvents() {
}

/**
* @param {string} tapTargetsSelector
* @returns {LH.Artifacts.TapTarget[]}
*/
/* istanbul ignore next */
function gatherTapTargets() {
function gatherTapTargets(tapTargetsSelector) {
/** @type {LH.Artifacts.TapTarget[]} */
const targets = [];

Expand All @@ -223,7 +225,7 @@ function gatherTapTargets() {
const tapTargetsWithClientRects = [];
tapTargetElements.forEach(tapTargetElement => {
// Filter out tap targets that are likely to cause false failures:
if (elementHasAncestorTapTarget(tapTargetElement)) {
if (elementHasAncestorTapTarget(tapTargetElement, tapTargetsSelector)) {
// This is usually intentional, either the tap targets trigger the same action
// or there's a child with a related action (like a delete button for an item)
return;
Expand Down Expand Up @@ -308,7 +310,6 @@ class TapTargets extends Gatherer {
*/
afterPass(passContext) {
const expression = `(function() {
const tapTargetsSelector = "${tapTargetsSelector}";
${pageFunctions.getElementsInDocumentString};
${disableFixedAndStickyElementPointerEvents.toString()};
${elementIsVisible.toString()};
Expand All @@ -328,7 +329,7 @@ class TapTargets extends Gatherer {
${pageFunctions.getNodeLabelString};
${gatherTapTargets.toString()};
return gatherTapTargets();
return gatherTapTargets("${tapTargetsSelector}");
})()`;

return passContext.driver.evaluateAsync(expression, {useIsolation: true});
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5814,16 +5814,16 @@ [email protected]:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.5.tgz#d7aa327bcecf518f9106ac6b8f003fa3bcea8566"
integrity sha1-16oye87PUY+RBqxrjwA/o7zqhWY=

[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==

minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6"
Expand Down

0 comments on commit d657e76

Please sign in to comment.