@@ -25,18 +25,13 @@ const isJSXIdentifierWithName = (name: TSESTree.JSXTagNameExpression, validNames
2525 * @returns boolean
2626 */
2727const hasLabelledChildImage = ( node : TSESTree . JSXElement ) : boolean => {
28- console . log ( "node::" , node ) ;
2928 if ( ! node . children || node . children . length === 0 ) {
3029 return false ;
3130 }
3231
3332 return flattenChildren ( node ) . some ( child => {
3433 if ( child . type === "JSXElement" && isJSXIdentifierWithName ( child . openingElement . name , mergedImageComponents ) ) {
3534 const attributes = child . openingElement . attributes ;
36- console . log ( "attributes::" , attributes ) ;
37- console . log ( "hasAccessibilityAttributes(attributes)" , hasAccessibilityAttributes ( attributes ) ) ;
38- console . log ( "!isImageHidden(attributes)" , ! isImageHidden ( attributes ) ) ;
39-
4035 return ! isImageHidden ( attributes ) && hasAccessibilityAttributes ( attributes ) ;
4136 }
4237 return false ;
@@ -68,23 +63,32 @@ const isImageHidden = (attributes: TSESTree.JSXOpeningElement["attributes"]): bo
6863 return true ;
6964 }
7065
71- // Check if the image has an `aria-label` attribute with a non-empty value
66+ // Check if the image has an `aria-label` or `aria-labelledby` attribute with a non-empty value
7267 const ariaLabelProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "aria-label" ) ;
68+ const ariaLabelledbyProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "aria-labelledby" ) ;
69+
7370 if ( ariaLabelProp ) {
7471 const ariaLabelValue = getPropValue ( ariaLabelProp ) ;
7572 if ( ariaLabelValue ) {
7673 return false ; // If `aria-label` is present and has a value, the image is not hidden
7774 }
7875 }
7976
77+ if ( ariaLabelledbyProp ) {
78+ const ariaLabelledbyValue = getPropValue ( ariaLabelledbyProp ) ;
79+ if ( ariaLabelledbyValue ) {
80+ return false ; // If `aria-labelledby` is present and has a value, the image is not hidden
81+ }
82+ }
83+
8084 // Check if the image has an `alt` attribute and return true if the `alt` value is falsy
8185 const altProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "alt" ) ;
8286 if ( altProp ) {
8387 const altValue = getPropValue ( altProp ) ;
8488 return ! altValue ; // Returns true if `altValue` is falsy (e.g., empty string, null, or undefined)
8589 }
8690
87- return true ; // If neither `alt` nor `aria-label ` is present, consider the image hidden
91+ return true ; // If neither `alt`, `aria-label`, nor `aria-labelledby ` is present, consider the image hidden
8892} ;
8993
9094export { hasLabelledChildImage , isImageHidden , hasAccessibilityAttributes , isJSXIdentifierWithName } ;
0 commit comments