Skip to content

Commit 3f6ef8d

Browse files
committed
Added changes in get-visible-child-text-child
1 parent a1eed77 commit 3f6ef8d

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

lib/commons/dom/get-visible-child-text-rects.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import cache from '../../core/base/cache';
1212
* @param {Element} node
1313
*/
1414
const getVisibleChildTextRects = memoize(
15-
function getVisibleChildTextRectsMemoized(node) {
15+
function getVisibleChildTextRectsMemoized(
16+
node,
17+
checkTextRectOutsideNodeBoundingRect = false,
18+
checkIsOutsideNodeBounds = true,
19+
includeOverflowHiddenRect = false
20+
) {
1621
const vNode = getNodeFromTree(node);
1722
const nodeRect = vNode.boundingClientRect;
1823
const clientRects = [];
@@ -24,18 +29,34 @@ const getVisibleChildTextRects = memoize(
2429
}
2530

2631
const contentRects = getContentRects(textNode);
27-
if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) {
28-
return;
32+
if (checkIsOutsideNodeBounds) {
33+
if (
34+
isOutsideNodeBounds(
35+
contentRects,
36+
nodeRect,
37+
checkTextRectOutsideNodeBoundingRect
38+
) &&
39+
!cache.get('ruleId')
40+
) {
41+
return;
42+
}
2943
}
3044

31-
clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
45+
if (includeOverflowHiddenRect) {
46+
clientRects.push(
47+
...filterHiddenRects(contentRects, overflowHiddenNodes)
48+
);
49+
} else {
50+
clientRects.push(...filterHiddenRects(contentRects, []));
51+
}
3252
});
3353

3454
// a11y-engine-domforge change
3555
if (
3656
clientRects.length <= 0 &&
3757
cache.get('ruleId') &&
38-
cache.get('ruleId') === 'resize-2x-zoom'
58+
cache.get('ruleId') === 'resize-2x-zoom' &&
59+
checkIsOutsideNodeBounds
3960
) {
4061
return [];
4162
}
@@ -72,10 +93,18 @@ function getContentRects(node) {
7293
* when determining the rect stack we will also use the midpoint
7394
* of the text rect to determine out of bounds
7495
*/
75-
function isOutsideNodeBounds(rects, nodeRect) {
96+
function isOutsideNodeBounds(
97+
rects,
98+
nodeRect,
99+
checkTextRectOutsideNodeBoundingRect = false
100+
) {
76101
return rects.some(rect => {
77102
const centerPoint = getRectCenter(rect);
78-
return !isPointInRect(centerPoint, nodeRect);
103+
if (checkTextRectOutsideNodeBoundingRect) {
104+
!isPointInRect(centerPoint, nodeRect) || rect.right > nodeRect.right;
105+
} else {
106+
return !isPointInRect(centerPoint, nodeRect);
107+
}
79108
});
80109
}
81110

0 commit comments

Comments
 (0)