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

Remove role requirement for img tags in require-valid-alt-text #2828

Conversation

yannbertrand
Copy link

@yannbertrand yannbertrand commented Mar 1, 2023

Affects require-valid-alt-text.

role should never be needed when using an img tag according to the W3C Nu Validator.

Closes #2190
Closes #2579.

@lin-ll lin-ll added the bug label Mar 2, 2023
@lin-ll lin-ll changed the title img tags should not have role attribute Remove role requirement for img tags in require-valid-alt-text Mar 2, 2023
Copy link
Contributor

@MelSumner MelSumner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this rule optional instead of removing it; it's weird but also the only way we can currently identify developer intent. It's also on the topic list for the next ARIA face to face.

@yannbertrand
Copy link
Author

Let's make this rule optional instead of removing it; it's weird but also the only way we can currently identify developer intent.

Thanks for the review. What do you mean by making the rule optional?

Should I remove these lines?

It's also on the topic list for the next ARIA face to face.

Interesting! Is there a planning of these events we can find somewhere?

@yannbertrand
Copy link
Author

I've added a commit to accept role attributes on img tags but do not apply any validation on them, rather than denying them.

@jaswilli
Copy link
Contributor

I think the intended changes here have become more urgent with the recent aria-query updates. Now both versions of an <img> with an empty alt tag are error conditions:

empty alt with presentation role:

$ echo '<img src="src" alt="" role="presentation">' | npx ember-template-lint --
undefined
  1:0  error  Use of redundant or invalid role: presentation on <img> detected.  no-redundant-role

empty alt without role:

$ echo '<img src="src" alt="">' | npx ember-template-lint --
undefined
  1:0  error  If the `alt` attribute is present and the value is an empty string, `role="presentation"` or `role="none"` must be present  require-valid-alt-text

'<img alt="" role="none" src="zoey.jpg">',
'<img alt="" role="presentation" src="zoey.jpg">',
'<img alt="a stylized graphic of a female hamster" src="zoey.jpg">',
'<img alt="a stylized graphic of a female hamster" role="presentation" src="zoey.jpg">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

role="presentation" and role="none" are not valid when alt is a non-empty string

Comment on lines -79 to -91
// if the role value is a mustache statement we can not validate it
if (hasAltAttribute && hasRole && !roleValue.type) {
if (
['none', 'presentation'].includes(roleValue.trim().toLowerCase()) &&
altValue !== ''
) {
this.logNode({
message:
'The `alt` attribute should be empty if `<img>` has `role` of `none` or `presentation`',
node,
});
}
}
Copy link
Contributor

@HeroicEric HeroicEric Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be removed. It is not valid to have a non-empty alt attribute if role="presentation" or role="none".

Removing this is not necessary to remove the requirement of setting role="presentation" or role="none" and doing so allows invalid markup like <img alt="non-empty-text" role="presentation" />

@yannbertrand
Copy link
Author

I'm closing this in favor of #2954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants