act-rules.github.io icon indicating copy to clipboard operation
act-rules.github.io copied to clipboard

Should img without role be failed for Element marked as decorative? [46ca7f]

Open WilcoFiers opened this issue 3 years ago • 6 comments

I'm concerned about implementing failed example 2 in our implementation:

<img src="/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label" />
<span hidden id="label">W3C logo</span>

I can easily imagine component code that ends up looking like this. Take this react component for example:

const Image = ({ alt = '', ...props }) => (<img alt={alt} {...props} />)

export default () => (<figure>
  <Image aria-labelledby="caption" src="my-image.png" />
  <figcaption id="caption">My wonderful caption</figcaption>
</figure>

This is a perfectly reasonable way to write a component, which then ends up being failed by the Element marked as decorative rule. I think this rule previously only reported on the explicit use of role=none / presentation. I'd prefer to go back to that, and turn failed example 2 into a pass.

WilcoFiers avatar May 31 '22 10:05 WilcoFiers

@WilcoFiers Looking back, it seems:

Of course, we can revisit all these decisions.


My current opinion is:

  • This is a Best Practice rule, even though people may build components that way (with empty alt and non-empty aria-label), I do not feel this is a good idea and I am fine flagging it as Best Practice.
  • As a tool vendor, we had the rule running in Alfa for more than a year and I have received no complain on this topic. So my data points to this not being a problem (or people ignoring it since it's a Best Practice).

So, I do not feel that the data we've gathered in the past two years requires us to revisit these decisions, and I'm still happy with how the rule is currently.

Jym77 avatar Jun 09 '22 13:06 Jym77

Plot twist… In ARIA 1.2, aria-label becomes prohibited on role of presentation.

So, the first thing is that <img alt="" aria-label="foo" /> is not valid anymore.

The second thing is that I understand that prohibited attributes should not trigger the presentational role conflict resolution, and this example is therefore having a role of presentation and not failing the rule…

presentational role conflict resolution:

If an element has global WAI-ARIA states or properties, user agents MUST ignore the presentation role and expose the element with its implicit role.

But global properties:

The following global states and properties are supported by all roles and by all base markup elements unless otherwise prohibited.

(emphasises mine) I understand that prohibited properties should not be considered as global, and not trigger the conflict. We may want to run some tests to be sure.


I suggest this is taken by the ARIA 1.2 committee since it relates to it.

Jym77 avatar Jul 26 '22 10:07 Jym77

Wouldn't have guessed this from the text, but you seem to be correct. At least as far as Chrome / Edge are concerned, aria-label and aria-labelledby no longer trigger conflict resolution for role=none / role=presentation. I.e. If you put aria-label on an h4 with role=none, Chrome no does not include that heading in the accessibility tree. Firefox and Safari still do though.

WilcoFiers avatar Aug 11 '22 14:08 WilcoFiers

Might be worth reaching out to ARIA group for clarification and whether prohibited attributes are supposed to trigger the conflict before we make changes 🤔

Jym77 avatar Aug 29 '22 08:08 Jym77

Related ARIA issue on this topic: https://github.com/w3c/aria/issues/1824

WilcoFiers avatar Oct 06 '22 10:10 WilcoFiers

Here are test results for alt="" with aria-label https://www.powermapper.com/tests/screen-readers/labelling/img-null-alt-aria-label/

dd8 avatar Oct 06 '22 10:10 dd8

This has been resolved with the ARIA 1.2 work.

WilcoFiers avatar Nov 17 '22 13:11 WilcoFiers