Skip to content

Commit 24e0c6e

Browse files
committed
Added logic for reflow in get-overflow-ancestors
1 parent df562e0 commit 24e0c6e

File tree

2 files changed

+69
-67
lines changed

2 files changed

+69
-67
lines changed

lib/commons/dom/get-overflow-hidden-ancestors.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ const getOverflowHiddenAncestors = memoize(
2727
) {
2828
ancestors.push(vNode);
2929
}
30-
} else {
31-
if (overflow === 'hidden' || overflow.includes('clip')) {
32-
ancestors.push(vNode);
33-
}
30+
} else if (
31+
cache.get('ruleId') &&
32+
cache.get('ruleId') === 'reflow' &&
33+
overflow.includes('hidden')
34+
) {
35+
ancestors.push(vNode);
36+
} else if (overflow === 'hidden' || overflow.includes('clip')) {
37+
ancestors.push(vNode);
3438
}
3539

3640
return ancestors.concat(getOverflowHiddenAncestors(vNode.parent));

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

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getNodeFromTree, memoize } from '../../core/utils';
1+
import { getNodeFromTree } from '../../core/utils';
22
import { sanitize } from '../text';
33
import { getIntersectionRect, getRectCenter, isPointInRect } from '../math';
44
import getOverflowHiddenAncestors from './get-overflow-hidden-ancestors';
@@ -11,74 +11,70 @@ import cache from '../../core/base/cache';
1111
* @instance
1212
* @param {Element} node
1313
*/
14-
const getVisibleChildTextRects = memoize(
15-
function getVisibleChildTextRectsMemoized(
16-
node,
14+
const getVisibleChildTextRects = (node, options = {}) => {
15+
const {
1716
checkTextRectOutsideNodeBoundingRect = false,
18-
checkIsOutsideNodeBounds = true,
19-
includeOverflowHiddenRect = false
20-
) {
21-
const vNode = getNodeFromTree(node);
22-
const nodeRect = vNode.boundingClientRect;
23-
const clientRects = [];
24-
const overflowHiddenNodes = getOverflowHiddenAncestors(vNode);
25-
26-
node.childNodes.forEach(textNode => {
27-
if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') {
28-
return;
29-
}
30-
31-
const contentRects = getContentRects(textNode);
32-
if (checkIsOutsideNodeBounds) {
33-
if (
34-
isOutsideNodeBounds(
35-
contentRects,
36-
nodeRect,
37-
checkTextRectOutsideNodeBoundingRect
38-
) &&
39-
!cache.get('ruleId')
40-
) {
41-
return;
42-
}
43-
}
17+
includeOutsideBounds = true,
18+
includeOverflowHidden = false,
19+
checkNoVisibleRectsIdentified = false
20+
} = options;
21+
const vNode = getNodeFromTree(node);
22+
const nodeRect = vNode.boundingClientRect;
23+
const clientRects = [];
24+
const overflowHiddenNodes = getOverflowHiddenAncestors(vNode);
4425

45-
if (includeOverflowHiddenRect) {
46-
clientRects.push(...filterHiddenRects(contentRects, []));
47-
} else {
48-
clientRects.push(
49-
...filterHiddenRects(contentRects, overflowHiddenNodes)
50-
);
51-
}
52-
});
26+
node.childNodes.forEach(textNode => {
27+
if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') {
28+
return;
29+
}
5330

54-
// a11y-engine-domforge change
31+
const contentRects = getContentRects(textNode);
5532
if (
56-
clientRects.length <= 0 &&
57-
cache.get('ruleId') &&
58-
cache.get('ruleId') === 'resize-2x-zoom' &&
59-
checkIsOutsideNodeBounds
33+
includeOutsideBounds &&
34+
isOutsideNodeBounds(
35+
contentRects,
36+
nodeRect,
37+
checkTextRectOutsideNodeBoundingRect
38+
) &&
39+
!cache.get('ruleId')
6040
) {
61-
return [];
41+
return;
6242
}
63-
/**
64-
* if all text rects are larger than the bounds of the node,
65-
* or goes outside of the bounds of the node, we need to use
66-
* the nodes bounding rect so we stay within the bounds of the
67-
* element.
68-
*
69-
* @see https://github.com/dequelabs/axe-core/issues/2178
70-
* @see https://github.com/dequelabs/axe-core/issues/2483
71-
* @see https://github.com/dequelabs/axe-core/issues/2681
72-
*
73-
* also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
74-
*
75-
* @see https://github.com/dequelabs/axe-core/issues/4253
76-
*/
77-
return clientRects.length
78-
? clientRects
79-
: filterHiddenRects([nodeRect], overflowHiddenNodes);
43+
44+
clientRects.push(
45+
...filterHiddenRects(
46+
contentRects,
47+
includeOverflowHidden ? [] : overflowHiddenNodes
48+
)
49+
);
50+
});
51+
52+
// a11y-engine-domforge change
53+
if (
54+
clientRects.length <= 0 &&
55+
((cache.get('ruleId') && cache.get('ruleId') === 'resize-2x-zoom') ||
56+
checkNoVisibleRectsIdentified)
57+
) {
58+
return [];
8059
}
81-
);
60+
/**
61+
* if all text rects are larger than the bounds of the node,
62+
* or goes outside of the bounds of the node, we need to use
63+
* the nodes bounding rect so we stay within the bounds of the
64+
* element.
65+
*
66+
* @see https://github.com/dequelabs/axe-core/issues/2178
67+
* @see https://github.com/dequelabs/axe-core/issues/2483
68+
* @see https://github.com/dequelabs/axe-core/issues/2681
69+
*
70+
* also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
71+
*
72+
* @see https://github.com/dequelabs/axe-core/issues/4253
73+
*/
74+
return clientRects.length
75+
? clientRects
76+
: filterHiddenRects([nodeRect], overflowHiddenNodes);
77+
};
8278
export default getVisibleChildTextRects;
8379

8480
function getContentRects(node) {
@@ -101,7 +97,9 @@ function isOutsideNodeBounds(
10197
return rects.some(rect => {
10298
const centerPoint = getRectCenter(rect);
10399
if (checkTextRectOutsideNodeBoundingRect) {
104-
!isPointInRect(centerPoint, nodeRect) || rect.right > nodeRect.right;
100+
return (
101+
!isPointInRect(centerPoint, nodeRect) || rect.right > nodeRect.right
102+
);
105103
} else {
106104
return !isPointInRect(centerPoint, nodeRect);
107105
}

0 commit comments

Comments
 (0)