@@ -25,18 +25,13 @@ const isJSXIdentifierWithName = (name: TSESTree.JSXTagNameExpression, validNames
25
25
* @returns boolean
26
26
*/
27
27
const hasLabelledChildImage = ( node : TSESTree . JSXElement ) : boolean => {
28
- console . log ( "node::" , node ) ;
29
28
if ( ! node . children || node . children . length === 0 ) {
30
29
return false ;
31
30
}
32
31
33
32
return flattenChildren ( node ) . some ( child => {
34
33
if ( child . type === "JSXElement" && isJSXIdentifierWithName ( child . openingElement . name , mergedImageComponents ) ) {
35
34
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
-
40
35
return ! isImageHidden ( attributes ) && hasAccessibilityAttributes ( attributes ) ;
41
36
}
42
37
return false ;
@@ -68,23 +63,32 @@ const isImageHidden = (attributes: TSESTree.JSXOpeningElement["attributes"]): bo
68
63
return true ;
69
64
}
70
65
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
72
67
const ariaLabelProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "aria-label" ) ;
68
+ const ariaLabelledbyProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "aria-labelledby" ) ;
69
+
73
70
if ( ariaLabelProp ) {
74
71
const ariaLabelValue = getPropValue ( ariaLabelProp ) ;
75
72
if ( ariaLabelValue ) {
76
73
return false ; // If `aria-label` is present and has a value, the image is not hidden
77
74
}
78
75
}
79
76
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
+
80
84
// Check if the image has an `alt` attribute and return true if the `alt` value is falsy
81
85
const altProp = getProp ( attributes as unknown as JSXOpeningElement [ "attributes" ] , "alt" ) ;
82
86
if ( altProp ) {
83
87
const altValue = getPropValue ( altProp ) ;
84
88
return ! altValue ; // Returns true if `altValue` is falsy (e.g., empty string, null, or undefined)
85
89
}
86
90
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
88
92
} ;
89
93
90
94
export { hasLabelledChildImage , isImageHidden , hasAccessibilityAttributes , isJSXIdentifierWithName } ;
0 commit comments