Skip to content

Commit

Permalink
fix(image): only overwrite current alt if new alt is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Arukuen committed Dec 3, 2024
1 parent 81f1002 commit d2d3215
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
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
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

0 comments on commit d2d3215

Please sign in to comment.