Skip to content

Commit

Permalink
img with alt maps to image
Browse files Browse the repository at this point in the history
according to https://www.w3.org/TR/html-aria/ and https://www.w3.org/TR/html-aam-1.0/,
only images with `alt` explicitly set will map to `img` role.
  • Loading branch information
khiga8 committed Jul 10, 2023
1 parent d21a25e commit ff41732
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rules/role-supports-aria-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ module.exports = {
// - Get the element’s name
const key = {name: getElementType(context, node)}
// - Get the element’s disambiguating attributes
for (const prop of ['aria-expanded', 'type', 'size', 'role', 'href', 'multiple', 'scope']) {
for (const prop of ['alt', 'aria-expanded', 'type', 'size', 'role', 'href', 'multiple', 'scope']) {
// - Only provide `aria-expanded` when it’s required for disambiguation
if (prop === 'aria-expanded' && key.name !== 'summary') continue
if (prop === 'alt' && key.name !== 'img') continue
const value = getPropValue(getProp(node.attributes, prop))
if (value) {
if (!('attributes' in key)) {
key.attributes = []
}
if (prop === 'href') {
if (prop === 'href' || prop === 'alt') {
key.attributes.push({name: prop})
} else {
key.attributes.push({name: prop, value})
Expand Down

0 comments on commit ff41732

Please sign in to comment.