color-contrast false-positives on empty text inputs #4260
Labels
color contrast
Color contrast issues
fix
Bug fixes
rules
Issue or false result from an axe-core rule
support
Milestone
Product
axe-core
Product Version
4.8.2
Latest Version
Issue Description
Expectation
We saw an example today of a customer site using a text input that used event handlers to apply different classes to the input element in empty vs nonempty states. The empty state used a
color
with < 4.5:1 contrast, but the non-empty state was fine. This shouldn't be a color contrast violation.Actual
This caused a
color-contrast
false positive becauseaxe-core
evaluates the text input contrast styling even when it contains no text:axe-core/lib/rules/color-contrast-matches.js
Lines 71 to 72 in f1af598
This gives extra-confusing results when the text input uses a
placeholder
- the contrast rule will currently ignore the placeholder text styling and instead evaluate as if the input contained a non-placeholder value, and any resulting violations will appear as if it's evaluated the placeholder text with a usually-incorrect foreground color.Placeholder text is generally subject to contrast requirements, so ideally we'd evaluate the placeholder (but using its foreground color, not the input's). But that can be a separate issue vs this false positive; for the purposes of this bug, either of "incomplete" or "not matched" would be an improvement over the current behavior.
How to Reproduce
Suggested new
color-contrast.html
integration test cases:Additional context
The "match text inputs without text" behavior appears to have been introduced a few years ago in #2130. The comment at the relevant line in
color-contrast-matches
suggests that it was done intentionally, but I didn't see a good explanation of why the intention was there in the PR or in the motivating issueThe text was updated successfully, but these errors were encountered: