Skip to content

Commit 118d104

Browse files
committed
tests
1 parent 00070a6 commit 118d104

File tree

5 files changed

+238
-95
lines changed

5 files changed

+238
-95
lines changed

lib/commons/dom/is-in-text-block.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import getComposedParent from './get-composed-parent';
22
import sanitize from '../text/sanitize';
33
import { getNodeFromTree, nodeLookup } from '../../core/utils';
44
import getRoleType from '../aria/get-role-type';
5+
import isFocusable from './is-focusable';
56

67
function walkDomNode(node, functor) {
78
if (functor(node.actualNode) !== false) {
@@ -19,8 +20,7 @@ function isBlock(node) {
1920
return blockLike.includes(display) || display.substr(0, 6) === 'table-';
2021
}
2122

22-
function isInlineBlockLike(node) {
23-
const { vNode } = nodeLookup(node);
23+
function isInlineBlockLike(vNode) {
2424
const display = vNode.getComputedStylePropertyValue('display');
2525
return inlineBlockLike.includes(display);
2626
}
@@ -47,30 +47,41 @@ function getBlockParent(node) {
4747
* @return {Boolean} [description]
4848
*/
4949
function isInTextBlock(node, { noLengthCompare, permissive = false } = {}) {
50-
if (isBlock(node)) {
50+
const { vNode, domNode } = nodeLookup(node);
51+
52+
if (isBlock(domNode)) {
5153
// Ignore if the link is a block
5254
return false;
5355
}
5456

5557
// Find all the text part of the parent block not in a link, and all the text in a link
56-
const virtualParent = getBlockParent(node);
58+
const virtualParent = getBlockParent(domNode);
5759

5860
// if the element is a block-like element, look at the siblings of the node and if any
5961
// are inline or text nodes then return the desired permissive option value so the
6062
// caller determine what to do with them.
61-
// widget parents and sibling elements should be ignored
6263
// @see https://github.com/dequelabs/axe-core/issues/4392
63-
if (isInlineBlockLike(node) && getRoleType(virtualParent) !== 'widget') {
64+
if (isInlineBlockLike(vNode)) {
65+
// widget parents should be ignored
66+
if (getRoleType(virtualParent) === 'widget' || isFocusable(virtualParent)) {
67+
return false;
68+
}
69+
6470
for (const siblingVNode of virtualParent.children) {
6571
if (
6672
siblingVNode.actualNode === node ||
67-
getRoleType(siblingVNode) === 'widget' ||
6873
// BR and HR elements break the line
6974
['br', 'hr'].includes(siblingVNode.props.nodeName)
7075
) {
7176
continue;
7277
}
7378

79+
// if there is a widget as a sibling we break out of the loop as we won't count two
80+
// widgets as being inline
81+
if (getRoleType(siblingVNode) === 'widget') {
82+
break;
83+
}
84+
7485
if (siblingVNode.props.nodeType === window.Node.TEXT_NODE) {
7586
if (sanitize(siblingVNode.props.nodeValue)) {
7687
return permissive;
@@ -110,7 +121,7 @@ function isInTextBlock(node, { noLengthCompare, permissive = false } = {}) {
110121
}
111122

112123
const nodeName = (currNode.nodeName || '').toUpperCase();
113-
if (currNode === node) {
124+
if (currNode === domNode) {
114125
inBrBlock = 1;
115126
}
116127
// BR and HR elements break the line

lib/rules/widget-not-inline-matches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const matchesFns = [
1414
(node, vNode) => isFocusable(vNode),
1515
// Skip nested widgets with tabindex=-1
1616
(node, vNode) => isInTabOrder(vNode) || !hasWidgetAncestorInTabOrder(vNode),
17-
node => !isInTextBlock(node, { noLengthCompare: true, permissive: false })
17+
node => !isInTextBlock(node, { noLengthCompare: true, permissive: true })
1818
];
1919

2020
function isWidgetType(vNode) {

0 commit comments

Comments
 (0)