diff --git a/src/block-components/image/edit.js b/src/block-components/image/edit.js index 4597bc4abd..89a2201cdd 100644 --- a/src/block-components/image/edit.js +++ b/src/block-components/image/edit.js @@ -137,7 +137,7 @@ const Controls = props => { imageWidthAttribute: width, imageHeightAttribute: height, imageExternalUrl: '', - ...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only set the alt if it's empty. + ...( image.alt ? { imageAlt: image.alt || '' } : {} ), // Only overwrite current alt if new alt is not empty. } ) } } /> diff --git a/src/block-components/image/image.js b/src/block-components/image/image.js index ac14edb808..c03692980c 100644 --- a/src/block-components/image/image.js +++ b/src/block-components/image/image.js @@ -269,7 +269,7 @@ const Image = memo( props => { onError={ () => setHasImageError( true ) } className={ imageClasses } src={ src || undefined } - alt={ striptags( props.alt || undefined ) } + alt={ striptags( props.alt || '' ) } title={ striptags( props.title || undefined ) } width={ props.width || undefined } height={ props.height || undefined } @@ -438,10 +438,10 @@ const ImageContent = props => { : undefined const propsToPass = {} - const alt = striptags( props.alt || undefined ) - if ( alt ) { - propsToPass.alt = alt - } + + // Allow explicit empty string for accessibility + propsToPass.alt = striptags( props.alt || '' ) + const title = striptags( props.title || undefined ) if ( title ) { propsToPass.title = title diff --git a/src/block-components/image/use-image.js b/src/block-components/image/use-image.js index 9a20cabc10..cca3764771 100644 --- a/src/block-components/image/use-image.js +++ b/src/block-components/image/use-image.js @@ -1,13 +1,10 @@ /** * WordPress Dependencies */ -import { useBlockAttributesContext, useBlockSetAttributesContext } from '~stackable/hooks' +import { useBlockSetAttributesContext } from '~stackable/hooks' export const useImage = () => { const setAttributes = useBlockSetAttributesContext() - const attributes = useBlockAttributesContext( attributes => ( { - imageAlt: attributes.imageAlt, - } ) ) const onChange = image => { setAttributes( { @@ -16,7 +13,7 @@ export const useImage = () => { imageHeightAttribute: image.height, imageWidthAttribute: image.width, imageExternalUrl: '', - ...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only add the image alt if it's empty. + ...( image.alt ? { imageAlt: image.alt || '' } : {} ), // Only overwrite current alt if new alt is not empty. } ) }