File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,18 @@ describe('props', () => {
5858 < div onClick = { k } > < span > < span > foo</ span > </ span > </ div > ;
5959 } ) ;
6060 } ) ;
61+
62+ it ( 'does not warn if there is an image with an alt attribute' , ( ) => {
63+ doNotExpectWarning ( assertions . props . onClick . NO_LABEL . msg , ( ) => {
64+ < div onClick = { k } > < img src = "#" alt = "Foo" /> </ div > ;
65+ } ) ;
66+ } ) ;
67+
68+ it ( 'warns if there is an image with an empty alt attribute' , ( ) => {
69+ expectWarning ( assertions . props . onClick . NO_LABEL . msg , ( ) => {
70+ < div onClick = { k } > < img src = "#" alt = "" /> </ div > ;
71+ } ) ;
72+ } ) ;
6173 } ) ;
6274
6375 describe ( 'when role="button"' , ( ) => {
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ var hasChildTextNode = (props, children) => {
2525 return ;
2626 else if ( typeof child === 'string' )
2727 hasText = true ;
28+ else if ( child . type === 'img' && child . props . alt )
29+ hasText = true ;
2830 else if ( child . props . children )
2931 hasText = hasChildTextNode ( child . props , child . props . children ) ;
3032 } ) ;
@@ -56,6 +58,7 @@ exports.props = {
5658 return (
5759 props [ 'aria-label' ] ||
5860 props [ 'aria-labelled-by' ] ||
61+ ( tagName === 'img' && props . alt ) ||
5962 hasChildTextNode ( props , children )
6063 ) ;
6164 }
You can’t perform that action at this time.
0 commit comments