Skip to content

Commit

Permalink
Merge pull request #840 from equalizedigital/william/7684799550/make-…
Browse files Browse the repository at this point in the history
…text-too-small-check-only-text-nodes

Refactor the text_size_too_small check
  • Loading branch information
pattonwebz authored Jan 22, 2025
2 parents e620f12 + b3d1abf commit ec10280
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pageScanner/checks/text-size-too-small.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ const SMALL_FONT_SIZE_THRESHOLD = 10;
export default {
id: 'text_size_too_small',
evaluate: ( node ) => {
// fails if the font size is less than or equal to 10px.
return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD;
// If the node has no text content then it can't have text that's too small.
if ( ! node.textContent.trim().length ) {
return false;
}

// Check if the node has any direct text nodes as children. For a node with no
// children, or with TEXT_NODE children, evaluate the nodes font size. This
// handles both leaf nodes and container elements with mixed content.
const hasTextChild = Array.from( node.childNodes ).some( ( child ) => child.nodeType === Node.TEXT_NODE );
if ( ! node.childNodes.length || hasTextChild ) {
return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD;
}

// No text nodes were found in direct children, and this is not a leaf node,
// so we can safely ignore font size checks.
return false;
},
};

0 comments on commit ec10280

Please sign in to comment.