color-contrast: shortTextContent and emptyValue override the actual incomplete reason when colors cannot be determined
Product
axe-core
Product Version
4.13.0 (develop @ eb854ed3)
Latest Version
- I have tested the issue with the latest version of the product
Issue Description
Expectation
When the foreground or background color cannot be determined, the incomplete result of color-contrast reports the reason why, e.g. bgOverlap when an element overlaps the text.
Actual
For a single character or an empty text input, the result is reported as shortTextContent or emptyValue instead. In color-contrast-evaluate.js, missing is first set to the reason a color is missing. The equalRatio / shortTextContent / emptyValue chain then overwrites it: without colors, contrast is null and truncatedResult is 0, so !isValid is always true. The message points to the text length or the empty value, although no contrast was measured.
How to Reproduce
<div style="position: relative; background: #fff">
<span id="target" style="color: #ddd">1</span>
<input id="empty" type="text" style="color: #eee; background: #fff" />
<div style="position: absolute; inset: 0; pointer-events: none"></div>
</div>#target is reported as incomplete with shortTextContent, #empty with emptyValue. Expected for both: bgOverlap.
With 12 as the span text and value="ab" on the input, both elements are reported with bgOverlap, so the overlap is detected and only the message is overwritten.
Additional context
In Angular Material, .mat-focus-indicator and .mdc-notched-outline are absolutely positioned on top of the text of list items and form fields. A badge with the text "1" inside a mat-list-item was reported as shortTextContent. After lifting the badge above the overlay, axe measured 8.87:1 and the badge passed.
This is related to, but independent of #3464. #3464 would remove the overlap for transparent overlays. This issue is about the reported reason whenever colors cannot be determined, regardless of what causes it.
The heuristics appear to assume measured colors: all existing shortTextContent and emptyValue tests use fixed colors, emptyValue (#5359, closes #4260) targets empty fields whose text color might change once a value is entered, and equalRatio can never be true without colors because getContrast returns null.
Open question: Is emptyValue perhaps intended even when the background is overlapped, in the sense of "set a value first, then re-check"? I could find no evidence for that in the tests or in #5359.
I have a fix with tests ready and will open a PR referencing this issue.
Generated with Claude Code
Source: dequelabs/axe-core