I'm an IT trainer, and I’d like to better understand a particular point to avoid saying anything incorrect to my trainees.
The criterion "2.5.3 Label in Name" (WCAG 2.2) tells that the aria-label should start with the visible label of the element. The goal is to ensure that voice command software, which relies on the visible name, can identify and click on the button.
Here are my questions:
What happens when several buttons share the same visible name, such as “Read the article” but have different aria-labels, for example: “Read the article about Accessibility”? How does the voice command software know which button to activate if the user tell "click on read the article"?
How does the user know whether they should ask the software to click on “Read the article” or “Read the article about Accessibility”? Since the software relies only on the aria-label that was read aloud to the user.
In that case, wouldn’t it be better to always use sr-only instead of aria-label, so that the text is actually inside the element and not in an attribute?
Example:
<button>
<span class="sr-only">Read the article about accessibility</span>
<span aria-hidden="true">Read the article</span>
</button>
- Alternatively, are voice command tools capable of detecting a button by its aria-label? In that case, the 2.5.3 rule wouldn't be necessary...
Thank you very much for your help!
sr-only?aria-labelattribute does not matter, voice control users will be able to use the element. Voice control only cares about the accessible name, it doesn't care how the accessible name is defined. So yes, voice control is able to access a button whose accessible name is set witharia-label, because it's the accessible name that matters, not how the accessible name is defined.