@@ -121,29 +121,34 @@ function elmPartiallyObscured(elm, bgElm, bgColor) {
121
121
* @param {Element } elm
122
122
*/
123
123
function includeMissingElements ( elmStack , elm ) {
124
- const elementMap = { 'TD' : 'TR' , 'TH' : 'TR' , 'INPUT' : 'LABEL' } ;
124
+ const elementMap = { 'TD' : [ 'TR' , 'TBODY' ] , ' TH' : [ 'TR' , 'THEAD' ] , ' INPUT' : [ 'LABEL' ] } ;
125
125
const tagArray = elmStack . map ( ( elm ) => {
126
126
return elm . tagName ;
127
127
} ) ;
128
128
let bgNodes = elmStack ;
129
+ //jshint maxdepth:7
129
130
for ( let candidate in elementMap ) {
130
- // check that TR or LABEL has paired nodeName from elementMap, but don't expect elm to be that candidate
131
+ // check that TR or LABEL has paired nodeName from elementMap, but don't expect elm to be that candidate
131
132
if ( tagArray . includes ( candidate ) ) {
132
- // look up the tree for a matching candidate
133
- let ancestorMatch = axe . commons . dom . findUp ( elm , elementMap [ candidate ] ) ;
134
- if ( ancestorMatch && elmStack . indexOf ( ancestorMatch ) === - 1 ) {
135
- // found an ancestor not in elmStack, and it overlaps
136
- let overlaps = axe . commons . dom . visuallyOverlaps ( elm . getBoundingClientRect ( ) , ancestorMatch ) ;
137
- if ( overlaps ) {
138
- // if target is in the elementMap, use its position.
139
- bgNodes . splice ( tagArray . indexOf ( candidate ) + 1 , 0 , ancestorMatch ) ;
133
+ for ( let candidateIndex in elementMap [ candidate ] ) {
134
+ if ( candidate . hasOwnProperty ( candidateIndex ) ) {
135
+ // look up the tree for a matching candidate
136
+ let ancestorMatch = axe . commons . dom . findUp ( elm , elementMap [ candidate ] [ candidateIndex ] ) ;
137
+ if ( ancestorMatch && elmStack . indexOf ( ancestorMatch ) === - 1 ) {
138
+ // found an ancestor not in elmStack, and it overlaps
139
+ let overlaps = axe . commons . dom . visuallyOverlaps ( elm . getBoundingClientRect ( ) , ancestorMatch ) ;
140
+ if ( overlaps ) {
141
+ // if target is in the elementMap, use its position.
142
+ bgNodes . splice ( tagArray . indexOf ( candidate ) + 1 , 0 , ancestorMatch ) ;
143
+ }
144
+ }
145
+ // tagName matches value
146
+ // (such as LABEL, when matching itself. It should be in the list, but Phantom skips it)
147
+ if ( elm . tagName === elementMap [ candidate ] [ candidateIndex ] && tagArray . indexOf ( elm . tagName ) === - 1 ) {
148
+ bgNodes . splice ( tagArray . indexOf ( candidate ) + 1 , 0 , elm ) ;
149
+ }
140
150
}
141
151
}
142
- // tagName matches value
143
- // (such as LABEL, when matching itself. It should be in the list, but Phantom skips it)
144
- if ( elm . tagName === elementMap [ candidate ] && tagArray . indexOf ( elm . tagName ) === - 1 ) {
145
- bgNodes . splice ( tagArray . indexOf ( candidate ) + 1 , 0 , elm ) ;
146
- }
147
152
}
148
153
}
149
154
return bgNodes ;
0 commit comments