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 = {
246
246
* @return {String }
247
247
*/
248
248
get selector ( ) {
249
+ if ( axe . _cache . get ( 'targetFormat' ) === 'ancestry' ) {
250
+ return this . spec . selector || [ getAncestry ( this . element ) ] ;
251
+ }
249
252
if ( axe . _cache . get ( 'runTypeAOpt' ) ) {
250
253
return this . spec . selector || [ generateSelectorWithShadow ( this . element ) ] ;
251
254
}
Original file line number Diff line number Diff line change @@ -13,8 +13,28 @@ function generateAncestry(node) {
13
13
nodeName !== 'body' &&
14
14
parent . children . length > 1
15
15
) {
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
+ }
18
38
}
19
39
20
40
return generateAncestry ( parent ) + ' > ' + nodeName + nthChild ;
You can’t perform that action at this time.
0 commit comments