target-offset check: targets containing shadow children cause false positives #4194
Closed
1 task done
Labels
Milestone
Product
axe-core
Product Version
4.8.2
Latest Version
Issue Description
Expectation
The
target-offset
check uses aget-target-rects
helper to break down a "target" into a collection of rects. Part of that work involves checking for any other elements that might be obscuring that target. That check is meant to treat children of the target as part of the target, but the way it does so isn't compatible with a target that contains shadow dom children - it assumes thatparentElement.contains(childElementWithinShadow)
will return true, but it doesn't. We already have a shadow-aware version ofcontains
(at/lib/core/utils/contains.js
) which this should use instead. We should audit for other uses of the wrongcontains
as part of fixing this issue. Bonus points for a new eslintno-restricted-syntax
config that warns us if we accidentally try to use the native one directly again in the future.This causes
getTargetRects
to treat the child of the target as obscuring the target. In the motivating case, this ends up treating the target as completely obscured, which causesgetTargetRects
to return an empty array.This in turn triggers a separate but related issue in
target-offset
- when a target's neighbor has an empty target rect array, it treats that neighbor as being 0 distance away from the target. It should treat fully-obscured neighbors as omitted from consideration for the check, not as being 0 distance away.Actual
In the repro snippet below,
axe.run({runOnly: 'target-size'})
emits a false positive violation for a case that ought to pass the SC's spacing exception.How to Reproduce
Additional context
The text was updated successfully, but these errors were encountered: