Skip to content

control-has-associated-label accepts whitespace as a label #918

@wobo-nate

Description

@wobo-nate

The problem

The control-has-associated-label rule currently accepts whitespace as an accessible label. This issue is exaggerated by the use of prettier which may introduce line breaks and other whitespace automatically, defeating the rule.

Examples

All of the below examples lack accessible labels.

<button></button> <!-- rule correctly flags invalid markup --> <button> </button> <!-- rule fails to flag invalid markup --> <button aria-label=""></button> <!-- rule correctly flags invalid markup --> <button aria-label=" "></button> <!-- rule fails to flag invalid markup -->

Suggested fix

Update mayHaveAccessibleLabel to .trim() the node's value before asserting truthiness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions