Skip to content

Commit 42d8eda

Browse files
fix (image block): allow empty alt tag
1 parent 558247b commit 42d8eda

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
@@ -244,6 +244,13 @@ const Controls = props => {
244244
/>
245245
) }
246246

247+
{ props.hasAlt && ! attributes.imageAlt && (
248+
<AdvancedToggleControl
249+
label={ __( 'Show Empty Alt Attribute', i18n ) }
250+
attribute="imageShowEmptyAlt"
251+
/>
252+
) }
253+
247254
<AdvancedRangeControl
248255
label={ __( 'Zoom', i18n ) }
249256
attribute="imageZoom"

src/block-components/image/image.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ const ImageContent = props => {
441441
const alt = striptags( props.alt || undefined )
442442
if ( alt ) {
443443
propsToPass.alt = alt
444+
} else if ( props.showEmptyAlt ) {
445+
propsToPass.alt = ''
444446
}
445447
const title = striptags( props.title || undefined )
446448
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)