From ff41732e28c361fb90d53de5434fad99f2d89a7b Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Mon, 10 Jul 2023 13:57:12 -0400 Subject: [PATCH] img with alt maps to image 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. --- lib/rules/role-supports-aria-props.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rules/role-supports-aria-props.js b/lib/rules/role-supports-aria-props.js index 370bb696..e1498fab 100644 --- a/lib/rules/role-supports-aria-props.js +++ b/lib/rules/role-supports-aria-props.js @@ -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})