Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/3376 fix/2955 image alt #3377

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/block-components/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
} )
} }
/>
Expand Down
10 changes: 5 additions & 5 deletions src/block-components/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/block-components/image/use-image.js
Original file line number Diff line number Diff line change
@@ -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( {
Expand All @@ -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.
} )
}

Expand Down
Loading