Skip to content

label-title-only fails when aria-labelledby points to a node with sr-only #5014

@albert-tarly

Description

@albert-tarly

Product

axe-core

Product Version

4.11.1

Latest Version

  • I have tested the issue with the latest version of the product

Issue Description

Expectation

When the input has an aria-labelledby pointing to a node with sr-only Tailwind class, it should pass

Actual

When the input has an aria-labelledby pointing to a node with sr-only Tailwind class, it fails with label-title-only violation:

 "Form elements should have a visible label (label-title-only)"
│ Fix all of the following:
│   Only title used to generate label for form element

How to Reproduce

<input type="file" name="profileImage" aria-labelledby="label" aria-describedby="hint" />
<div id="label" class="sr-only">Upload a file</div>
<span id="hint">Max 5 MB, .jpg or .png only</span>

Fails

<input type="file" name="profileImage" aria-labelledby="label" aria-describedby="hint" />
<div id="label">Upload a file</div>
<span id="hint">Max 5 MB, .jpg or .png only</span>

Passes

Additional Context

sr-only is used in Tailwind to only expose elements to screen readers, but axe doesn't seem to consider this when validating label-title-only

Metadata

Metadata

Assignees

No one assigned

    Labels

    best practicefixBug fixesrulesIssue or false result from an axe-core rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions