Skip to content

Commit

Permalink
fix (image alt): only override the image alt if it's empty and don't …
Browse files Browse the repository at this point in the history
…remove it when clearing the image. fixes gambitph#2524
  • Loading branch information
bfintal committed Dec 26, 2022
1 parent 2564810 commit 89230c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/block-components/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const Controls = props => {
imageUrl: '',
imageWidthAttribute: '',
imageHeightAttribute: '',
imageAlt: '',
} ) }
onChange={ image => {
// Get the URL of the currently selected image size.
Expand All @@ -115,7 +114,7 @@ const Controls = props => {
imageUrl: url,
imageWidthAttribute: width,
imageHeightAttribute: height,
imageAlt: image.alt || '',
...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only set the alt if it's empty.
} )
} }
/>
Expand Down
8 changes: 5 additions & 3 deletions src/block-components/image/use-image.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/**
* WordPress Dependencies
*/
import { useBlockSetAttributesContext } from '~stackable/hooks'
import { useBlockAttributesContext, useBlockSetAttributesContext } from '~stackable/hooks'

export const useImage = () => {
const setAttributes = useBlockSetAttributesContext()
const attributes = useBlockAttributesContext( attributes => ( {
imageAlt: attributes.imageAlt,
} ) )

const onChange = image => {
setAttributes( {
imageUrl: image.url,
imageId: image.id,
imageHeightAttribute: image.height,
imageWidthAttribute: image.width,
imageAlt: image.alt,
...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only add the image alt if it's empty.
} )
}

Expand Down Expand Up @@ -79,7 +82,6 @@ export const useImage = () => {
imageId: '',
imageHeightAttribute: '',
imageWidthAttribute: '',
imageAlt: '',
} )
}

Expand Down

0 comments on commit 89230c4

Please sign in to comment.