Skip to content

Commit d0c356b

Browse files
authored
Merge pull request #125 from browserstack/release_3.6.0
Release 3.6.0
2 parents 4b49026 + 5370d4c commit d0c356b

File tree

3 files changed

+90
-49
lines changed

3 files changed

+90
-49
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-4x-zoom-scroll' &&
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: 71 additions & 44 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,53 +11,70 @@ import cache from '../../core/base/cache';
1111
* @instance
1212
* @param {Element} node
1313
*/
14-
const getVisibleChildTextRects = memoize(
15-
function getVisibleChildTextRectsMemoized(node) {
16-
const vNode = getNodeFromTree(node);
17-
const nodeRect = vNode.boundingClientRect;
18-
const clientRects = [];
19-
const overflowHiddenNodes = getOverflowHiddenAncestors(vNode);
14+
const getVisibleChildTextRects = (node, options = {}) => {
15+
const {
16+
checkTextRectOutsideNodeBoundingRect = false,
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);
2025

21-
node.childNodes.forEach(textNode => {
22-
if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') {
23-
return;
24-
}
25-
26-
const contentRects = getContentRects(textNode);
27-
if (isOutsideNodeBounds(contentRects, nodeRect) && !cache.get('ruleId')) {
28-
return;
29-
}
30-
31-
clientRects.push(...filterHiddenRects(contentRects, overflowHiddenNodes));
32-
});
26+
node.childNodes.forEach(textNode => {
27+
if (textNode.nodeType !== 3 || sanitize(textNode.nodeValue) === '') {
28+
return;
29+
}
3330

34-
// a11y-engine-domforge change
31+
const contentRects = getContentRects(textNode);
3532
if (
36-
clientRects.length <= 0 &&
37-
cache.get('ruleId') &&
38-
cache.get('ruleId') === 'resize-2x-zoom'
33+
includeOutsideBounds &&
34+
isOutsideNodeBounds(
35+
contentRects,
36+
nodeRect,
37+
checkTextRectOutsideNodeBoundingRect
38+
) &&
39+
(!cache.get('ruleId') || cache.get('ruleId') === 'reflow-4x-zoom-scroll')
3940
) {
40-
return [];
41+
return;
4142
}
42-
/**
43-
* if all text rects are larger than the bounds of the node,
44-
* or goes outside of the bounds of the node, we need to use
45-
* the nodes bounding rect so we stay within the bounds of the
46-
* element.
47-
*
48-
* @see https://github.com/dequelabs/axe-core/issues/2178
49-
* @see https://github.com/dequelabs/axe-core/issues/2483
50-
* @see https://github.com/dequelabs/axe-core/issues/2681
51-
*
52-
* also need to resize the nodeRect to fit within the bounds of any overflow: hidden ancestors.
53-
*
54-
* @see https://github.com/dequelabs/axe-core/issues/4253
55-
*/
56-
return clientRects.length
57-
? clientRects
58-
: 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 [];
5959
}
60-
);
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+
};
6178
export default getVisibleChildTextRects;
6279

6380
function getContentRects(node) {
@@ -72,10 +89,20 @@ function getContentRects(node) {
7289
* when determining the rect stack we will also use the midpoint
7390
* of the text rect to determine out of bounds
7491
*/
75-
function isOutsideNodeBounds(rects, nodeRect) {
92+
function isOutsideNodeBounds(
93+
rects,
94+
nodeRect,
95+
checkTextRectOutsideNodeBoundingRect = false
96+
) {
7697
return rects.some(rect => {
7798
const centerPoint = getRectCenter(rect);
78-
return !isPointInRect(centerPoint, nodeRect);
99+
if (checkTextRectOutsideNodeBoundingRect) {
100+
return (
101+
!isPointInRect(centerPoint, nodeRect) || rect.right > nodeRect.right
102+
);
103+
} else {
104+
return !isPointInRect(centerPoint, nodeRect);
105+
}
79106
});
80107
}
81108

lib/rules/autocomplete-a11y-matches.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ function quantityField(node) {
9292
});
9393
}
9494

95+
function isReadOnly(node) {
96+
return node.hasAttribute('readonly');
97+
}
98+
99+
function isCombobox(node) {
100+
return node.getAttribute('role') === 'combobox';
101+
}
102+
95103
function autocompleteA11yMatches(node, virtualNode) {
96104
const a11yEngineFlag = true;
97105
/* the flag is used to tell autocomplete matcher that it is being called
@@ -100,7 +108,9 @@ function autocompleteA11yMatches(node, virtualNode) {
100108
return (
101109
autocompleteMatches(node, virtualNode, a11yEngineFlag) &&
102110
!nodeIsASearchFunctionality(node) &&
103-
!quantityField(node)
111+
!quantityField(node) &&
112+
!isReadOnly(node) &&
113+
!isCombobox(node)
104114
);
105115
}
106116

0 commit comments

Comments
 (0)