File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,9 @@ DqElement.prototype = {
246246 * @return {String }
247247 */
248248 get selector ( ) {
249+ if ( axe . _cache . get ( 'targetFormat' ) === 'ancestry' ) {
250+ return this . spec . selector || [ getAncestry ( this . element ) ] ;
251+ }
249252 if ( axe . _cache . get ( 'runTypeAOpt' ) ) {
250253 return this . spec . selector || [ generateSelectorWithShadow ( this . element ) ] ;
251254 }
Original file line number Diff line number Diff line change @@ -13,8 +13,28 @@ function generateAncestry(node) {
1313 nodeName !== 'body' &&
1414 parent . children . length > 1
1515 ) {
16- const index = Array . prototype . indexOf . call ( parent . children , node ) + 1 ;
17- nthChild = `:nth-child(${ index } )` ;
16+ let index = 0 ;
17+ if ( parent . nodeName === 'BODY' ) {
18+ let count = 0 ;
19+ // Single pass over siblings: count valid children & locate node position.
20+ for (
21+ let sib = parent . firstElementChild ;
22+ sib ;
23+ sib = sib . nextElementSibling
24+ ) {
25+ if ( sib . hasAttribute ( 'data-percy-injected' ) ) {
26+ continue ;
27+ }
28+ count ++ ;
29+ if ( sib === node ) {
30+ index = count ;
31+ }
32+ }
33+ nthChild = count > 1 ? `:nth-child(${ index } )` : '' ;
34+ } else {
35+ index = Array . prototype . indexOf . call ( parent . children , node ) + 1 ;
36+ nthChild = `:nth-child(${ index } )` ;
37+ }
1838 }
1939
2040 return generateAncestry ( parent ) + ' > ' + nodeName + nthChild ;
You can’t perform that action at this time.
0 commit comments