Skip to content

Commit

Permalink
Lock the caption if the image is in a pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Feb 12, 2024
1 parent 7ab1db6 commit 94ad853
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ export default function Image( {
lockHrefControls = false,
lockAltControls = false,
lockTitleControls = false,
lockCaption = false,
} = useSelect(
( select ) => {
if ( ! isSingleSelected ) {
Expand All @@ -432,6 +433,10 @@ export default function Image( {
// Disable editing the link of the URL if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the link on the frontend.
hasParentPattern,
lockCaption:
// Disable editing the caption if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the caption on the frontend.
hasParentPattern,
lockAltControls:
!! altBinding &&
getBlockBindingsSource( altBinding?.source )
Expand Down Expand Up @@ -788,14 +793,23 @@ export default function Image( {
which causes duplicated image upload. */ }
{ ! temporaryURL && controls }
{ img }
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={ isSingleSelected && hasNonContentControls }
/>

{ lockCaption && (
<figcaption>{ attributes.caption?.toHTMLString() }</figcaption>
) }

{ ! lockCaption && (
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={
isSingleSelected && hasNonContentControls
}
/>
) }
</>
);
}

0 comments on commit 94ad853

Please sign in to comment.