From 32a1ad6cf77d3331e95ee5d35ab723607bf88712 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Tue, 21 Jan 2025 15:07:55 +0000 Subject: [PATCH] Refactor the text_size_too_small check to try more accurately determine if the node is the one to analyse It looks now at child nodes if they exist for TEXT_NODE types --- src/pageScanner/checks/text-size-too-small.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pageScanner/checks/text-size-too-small.js b/src/pageScanner/checks/text-size-too-small.js index 5bf09a25..bbea3eba 100644 --- a/src/pageScanner/checks/text-size-too-small.js +++ b/src/pageScanner/checks/text-size-too-small.js @@ -12,7 +12,25 @@ 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; + } + + // If the node has no child nodes, then consider it as a text node itself and check it. + if ( ! node.childNodes.length ) { + return fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD; + } + + // Check onlychild nodes of the element that are text nodes. + let isTextTooSmall = false; + node.childNodes.forEach( ( child ) => { + if ( child.nodeType === Node.TEXT_NODE ) { + if ( fontSizeInPx( node ) <= SMALL_FONT_SIZE_THRESHOLD ) { + isTextTooSmall = true; + } + } + } ); + return isTextTooSmall; }, };