Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

label-content-name-mismatch should consider cases that don't use aria-label (such as sr-only elements) #4261

Open
botic opened this issue Nov 30, 2023 · 3 comments
Labels
feat New feature or enhancement
Milestone

Comments

@botic
Copy link

botic commented Nov 30, 2023

Product

axe-core

Feature Description

Take the following HTML with accessible names defined via aria-label:

<button aria-label="1: View all">1: View all</button>
<button aria-label="2: View all videos">2: View all</button>
<button aria-label="3: View all of my videos">3: View videos</button>

Variants 1 and 2 pass the "label-content-name-mismatch" rule because it just checks the prefix of the aria-label against the actual text content of the node. Variant 3 fails the test because all of my is inserted in the middle of the label, but is clearly a more descriptive label for the given button.

The "label-content-name-mismatch" rule should be more relaxed and just check if all words of the accessible name are in occuring in the same order as in the visible text.

Here a screenshot of a concrete example in Lightouse 11 with axe-core 4.8:

grafik

Should pass

<button aria-label="one">one</button>
<button aria-label="one two">one</button>
<button aria-label="one two three">one three</button>

Should fail

<button aria-label="one">two</button>
<button aria-label="three two one">one two three</button>
@botic botic added feat New feature or enhancement ungroomed Ticket needs a maintainer to prioritize and label labels Nov 30, 2023
@straker
Copy link
Contributor

straker commented Nov 30, 2023

Thanks for the issue. The reason the example provided fails is that the accessible name of the button does not match the beginning of the aria-label. This follows Technique G208 of how to meet SC 2.5.3 in that the visible button text matches the beginning of the accessible name. Due to how speech recognition software works, trying to activate the button by saying "view videos" may not match the button's accessible name of "view all my videos" since there are words in between. It is best to avoid these problems by making sure the visible text label of the button also matches the beginning of the accessible name.

In situations where the visible label is considered inadequate as the accessible name, it is possible to supplement text in the accessible name. However, in order to meet 2.5.3 Label in Name, the text string that makes up the visible label must occur in its entirety in the accessible name. In most situations, where it is felt that additional context is needed, it is recommended that the visible text should precede the additional text. When authors make sure that the visible label of a control is included, intact, in the accessible name of that control, speech input users can be confident that their input will be correctly interpreted.

@botic
Copy link
Author

botic commented Nov 30, 2023

Thanks for pointing this out! After some more testing with G208 in mind: I think the test could be stricter to catch workarounds with CSS. But this might be impossible to detect via automated testing.

Button number 3 fails as before, but recreating the same effect with the infamous sr-only screenreader-only CSS class didn't trigger axe-core. Since the visible label does not match the elements text, speech recognition might fail on finding it in the DOM. An acceptable solution is the last button, where the more specific information is carried out as a prefix and thus keeps the visible label intact.

<ol>
  <li><button aria-label="View all">View all</button>
  <li><button aria-label="View all videos">View all</button>
  <li><button aria-label="View all of my videos">View videos</button>
  <li><button>View <span class="sr-only">all of my</span> videos</button>
  <li><button aria-label="Your library - view videos">View videos</button>
</ol>
grafik

Thanks for pointing me in the right direction and I hope my additional feedback is helpful on this topic.

@straker straker removed the ungroomed Ticket needs a maintainer to prioritize and label label Dec 7, 2023
@straker straker added this to the Axe-core 4.9 milestone Dec 7, 2023
@straker
Copy link
Contributor

straker commented Dec 7, 2023

Thanks for the suggestion. We'll look into what it would take to implement this. Since the original issue and this suggestion are a bit different, I'm going to update the title of the issue to describe the feature rather than the bug so we can track this easier.

@straker straker changed the title label-content-name-mismatch rule should allow filled up accessible names label-content-name-mismatch should consider cases that don't use aria-label (such as sr-only elements) Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants