Skip to content

No implicit role for <img> with alt="" #504

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

Merged
merged 2 commits into from
Dec 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions __tests__/src/rules/role-supports-aria-props-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,8 @@ ruleTester.run('role-supports-aria-props', rule, {
// this will have global
{ code: '<link aria-checked />' },

// IMG TESTS - implicit role is `presentation`
{ code: '<img alt="" aria-atomic />' },
{ code: '<img alt="" aria-busy />' },
Copy link
Member

Choose a reason for hiding this comment

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

why remove all these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the implicit role is not presentation.
The only way to change the role to presentation is by assigning it in the attribute.
But I didn't see any test case in this file have an assigned role.
All cases are using other ways to switch role, e.g. change value of type

{ code: '<img alt="" aria-controls />' },
{ code: '<img alt="" aria-describedby />' },
{ code: '<img alt="" aria-disabled />' },
{ code: '<img alt="" aria-dropeffect />' },
{ code: '<img alt="" aria-flowto />' },
{ code: '<img alt="" aria-grabbed />' },
{ code: '<img alt="" aria-haspopup />' },
{ code: '<img alt="" aria-hidden />' },
{ code: '<img alt="" aria-invalid />' },
{ code: '<img alt="" aria-label />' },
{ code: '<img alt="" aria-labelledby />' },
{ code: '<img alt="" aria-live />' },
{ code: '<img alt="" aria-owns />' },
{ code: '<img alt="" aria-relevant />' },
// IMG TESTS - no implicit role
{ code: '<img alt="" aria-checked />' },

// this will have role of `img`
{ code: '<img alt="foobar" aria-busy />' },
Expand Down Expand Up @@ -444,8 +429,8 @@ ruleTester.run('role-supports-aria-props', rule, {
errors: [errorMessage('aria-checked', 'link', 'link', true)],
},
{
code: '<img alt="" aria-checked />',
errors: [errorMessage('aria-checked', 'presentation', 'img', true)],
code: '<img alt="foobar" aria-checked />',
errors: [errorMessage('aria-checked', 'img', 'img', true)],
},
{
code: '<menu type="toolbar" aria-checked />',
Expand Down
2 changes: 1 addition & 1 deletion src/util/implicitRoles/img.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function getImplicitRoleForImg(attributes) {
const alt = getProp(attributes, 'alt');

if (alt && getLiteralPropValue(alt) === '') {
return 'presentation';
return '';
}

return 'img';
Expand Down