@@ -281,13 +281,29 @@ Image.addStyles( blockStyles, {
281281 const blockStyle = getBlockStyle ( variations , className )
282282 return ! [ 'list' , 'horizontal' , 'horizontal-2' , 'portfolio' , 'portfolio-2' , 'vertical-card-2' ] . includes ( blockStyle ?. name )
283283 } ,
284+ saveEnableWidthCallback : getAttribute => {
285+ const className = getAttribute ( 'className' )
286+ const imageHasLink = getAttribute ( 'imageHasLink' )
287+ const blockStyle = getBlockStyle ( variations , className )
288+
289+ if ( [ 'horizontal' , 'horizontal-2' ] . includes ( blockStyle ?. name ) ) {
290+ // If the image has a link and the width unit is %, return false
291+ // because the we have set a custom selector for the image width that uses the % unit.
292+ if ( imageHasLink && ( getAttribute ( 'imageWidthUnit' ) === '%' ||
293+ getAttribute ( 'imageWidthUnitTablet' ) === '%' ) ) {
294+ return false
295+ }
296+ return true
297+ }
298+ return true
299+ } ,
284300 selectorCallback : ( getAttribute , _attributes , _clientId , props ) => {
285301 const className = getAttribute ( 'className' )
286302 const blockStyle = getBlockStyle ( variations , className )
287303 const imageHasLink = getAttribute ( 'imageHasLink' )
288304
289305 const selector = props . selector
290- if ( [ 'list' , 'horizontal' , 'horizontal-2' ] . includes ( blockStyle ?. name ) && imageHasLink ) {
306+ if ( [ 'list' ] . includes ( blockStyle ?. name ) && imageHasLink ) {
291307 return Array . isArray ( selector )
292308 ? [ ...selector , `${ itemSelector } .stk-block-posts__image-link` ]
293309 : [ selector , `${ itemSelector } .stk-block-posts__image-link` ]
@@ -299,7 +315,7 @@ Image.addStyles( blockStyles, {
299315 const blockStyle = getBlockStyle ( variations , className )
300316 const imageHasLink = getAttribute ( 'imageHasLink' )
301317
302- if ( [ 'list' , 'horizontal' , 'horizontal-2' ] . includes ( blockStyle ?. name ) && imageHasLink ) {
318+ if ( [ 'list' ] . includes ( blockStyle ?. name ) && imageHasLink ) {
303319 return 'flexBasis'
304320 }
305321 return 'width'
0 commit comments