Skip to content

Commit 02a6427

Browse files
authored
fix (image block): allow empty alt tag (#3404)
Co-authored-by: [email protected] <>
1 parent c8a36d1 commit 02a6427

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/block-components/image/attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export const addAttributes = ( attrObject, options = {} ) => {
2929
attribute: 'alt',
3030
default: '',
3131
},
32+
imageShowEmptyAlt: {
33+
type: 'boolean',
34+
default: false,
35+
},
3236
imageAspectRatio: {
3337
stkResponsive: true,
3438
type: 'string',

src/block-components/image/edit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ const Controls = props => {
368368
/>
369369
) }
370370

371+
{ props.hasAlt && ! attributes.imageAlt && (
372+
<AdvancedToggleControl
373+
label={ __( 'Show Empty Alt Attribute', i18n ) }
374+
attribute="imageShowEmptyAlt"
375+
/>
376+
) }
377+
371378
<AdvancedRangeControl
372379
label={ __( 'Zoom', i18n ) }
373380
attribute="imageZoom"

src/block-components/image/image.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ const ImageContent = props => {
471471
const alt = striptags( props.alt || undefined )
472472
if ( alt ) {
473473
propsToPass.alt = alt
474+
} else if ( props.showEmptyAlt ) {
475+
propsToPass.alt = ''
474476
}
475477
const title = striptags( props.title || undefined )
476478
if ( title ) {

src/block-components/image/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Image.Content = props => {
152152
imageId={ attributes.imageId }
153153
imageURL={ attributes.imageUrl }
154154
alt={ alt || attributes.imageAlt }
155+
showEmptyAlt={ attributes.imageShowEmptyAlt }
155156
size={ attributes.imageSize }
156157
src={ src || attributes.imageUrl || attributes.imageExternalUrl }
157158

0 commit comments

Comments
 (0)