Skip to content

Commit

Permalink
Ensure "disable overrides" button is active for image blocks with cap…
Browse files Browse the repository at this point in the history
…tions or links (#62948)

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
  • Loading branch information
3 people authored and gutenbergplugin committed Jun 28, 2024
1 parent 6155b66 commit b9db3e1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/patterns/src/components/pattern-overrides-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function PatternOverridesControls( {

const hasName = !! attributes.metadata?.name;
const defaultBindings = attributes.metadata?.bindings?.__default;
const allowOverrides =
const hasOverrides =
hasName && defaultBindings?.source === PATTERN_OVERRIDES_BINDING_SOURCE;
const isConnectedToOtherSources =
defaultBindings?.source &&
Expand Down Expand Up @@ -79,13 +79,14 @@ function PatternOverridesControls( {
blockName === 'core/image' &&
( !! attributes.caption?.length || !! attributes.href?.length );

const helpText = hasUnsupportedImageAttributes
? __(
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
)
: __(
'Allow changes to this block throughout instances of this pattern.'
);
const helpText =
! hasOverrides && hasUnsupportedImageAttributes
? __(
`Overrides currently don't support image captions or links. Remove the caption or link first before enabling overrides.`
)
: __(
'Allow changes to this block throughout instances of this pattern.'
);

return (
<>
Expand All @@ -101,16 +102,18 @@ function PatternOverridesControls( {
variant="secondary"
aria-haspopup="dialog"
onClick={ () => {
if ( allowOverrides ) {
if ( hasOverrides ) {
setShowDisallowOverridesModal( true );
} else {
setShowAllowOverridesModal( true );
}
} }
disabled={ hasUnsupportedImageAttributes }
disabled={
! hasOverrides && hasUnsupportedImageAttributes
}
__experimentalIsFocusable
>
{ allowOverrides
{ hasOverrides
? __( 'Disable overrides' )
: __( 'Enable overrides' ) }
</Button>
Expand Down

0 comments on commit b9db3e1

Please sign in to comment.