@@ -2,6 +2,7 @@ import getComposedParent from './get-composed-parent';
22import sanitize from '../text/sanitize' ;
33import { getNodeFromTree , nodeLookup } from '../../core/utils' ;
44import getRoleType from '../aria/get-role-type' ;
5+ import isFocusable from './is-focusable' ;
56
67function 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 */
4949function 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
0 commit comments