diff --git a/lib/rules/a11y-svg-has-accessible-name.js b/lib/rules/a11y-svg-has-accessible-name.js index e8c92a8f..45e675fd 100644 --- a/lib/rules/a11y-svg-has-accessible-name.js +++ b/lib/rules/a11y-svg-has-accessible-name.js @@ -16,10 +16,14 @@ module.exports = { const elementType = getElementType(context, node) if (elementType !== 'svg') return - // Check if there is a nested title element that is the first child of the `` + // Check if there is a nested title element that is the first non-whitespace child of the `` + const childrenWithoutWhitespace = node.parent.children?.filter(({type, value}) => + type === 'JSXText' ? value.trim() !== '' : type !== 'JSXText', + ) + const hasNestedTitleAsFirstChild = - node.parent.children?.[0]?.type === 'JSXElement' && - node.parent.children?.[0]?.openingElement?.name?.name === 'title' + childrenWithoutWhitespace?.[0]?.type === 'JSXElement' && + childrenWithoutWhitespace?.[0]?.openingElement?.name?.name === 'title' // Check if `aria-label` or `aria-labelledby` is set const hasAccessibleName = hasProp(node.attributes, 'aria-label') || hasProp(node.attributes, 'aria-labelledby') diff --git a/tests/a11y-svg-has-accessible-name.js b/tests/a11y-svg-has-accessible-name.js index c708ee9a..62442132 100644 --- a/tests/a11y-svg-has-accessible-name.js +++ b/tests/a11y-svg-has-accessible-name.js @@ -19,6 +19,12 @@ ruleTester.run('a11y-svg-has-accessible-name', rule, { { code: "Circle with a black outline and red fill", }, + { + code: ` + Circle with a black outline and red fill + + `, + }, { code: "", }, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy