Skip to content

Commit d2d3215

Browse files
committed
fix(image): only overwrite current alt if new alt is not empty
1 parent 81f1002 commit d2d3215

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/block-components/image/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const Controls = props => {
137137
imageWidthAttribute: width,
138138
imageHeightAttribute: height,
139139
imageExternalUrl: '',
140-
...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only set the alt if it's empty.
140+
...( image.alt ? { imageAlt: image.alt || '' } : {} ), // Only overwrite current alt if new alt is not empty.
141141
} )
142142
} }
143143
/>

src/block-components/image/use-image.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/**
22
* WordPress Dependencies
33
*/
4-
import { useBlockAttributesContext, useBlockSetAttributesContext } from '~stackable/hooks'
4+
import { useBlockSetAttributesContext } from '~stackable/hooks'
55

66
export const useImage = () => {
77
const setAttributes = useBlockSetAttributesContext()
8-
const attributes = useBlockAttributesContext( attributes => ( {
9-
imageAlt: attributes.imageAlt,
10-
} ) )
118

129
const onChange = image => {
1310
setAttributes( {
@@ -16,7 +13,7 @@ export const useImage = () => {
1613
imageHeightAttribute: image.height,
1714
imageWidthAttribute: image.width,
1815
imageExternalUrl: '',
19-
...( attributes.imageAlt ? {} : { imageAlt: image.alt || '' } ), // Only add the image alt if it's empty.
16+
...( image.alt ? { imageAlt: image.alt || '' } : {} ), // Only overwrite current alt if new alt is not empty.
2017
} )
2118
}
2219

0 commit comments

Comments
 (0)